brand.js
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* 品牌一览
* @author: liangzhifeng<zhifeng.liang@yoho.cn>
* @date: 2015/10/23
*/
var $ = require('jquery'),
Hammer = require('hammer'),
Swiper = require('yoho.iswiper'),
lazyLoad = require('yoho.lazyload');
var swiper,
$brandList = $('.brand-list');
var searchH = $('.newbrand-search').outerHeight(),
headerH = $('.yoho-header').outerHeight(),
brandSwipe = parseInt(searchH) + parseInt(headerH) - 1;
var myHammer;
swiper = new Swiper('.swiper-container', {
lazyLoading: true,
loop: true,
autoplay: 3000,
pagination: '.swiper-pagination .pagination-inner'
});
lazyLoad($('img.lazy'));
$('.yoho-header').css({
'z-index': 2,
position: 'fixed'
});
$('.banner-top').css('padding-top', '90px');
if ($brandList.length > 0) {
$(window).scroll(function() {
var scrTop = $(window).scrollTop();
$('.brand-list').each(function() {
var offTop = $(this).offset().top - brandSwipe;
if (scrTop >= offTop) {
$brandList.find('.title-bar').css('position', 'static');
$(this).find('.title-bar').css({
position: 'fixed',
top: brandSwipe
});
} else {
$(this).find('.title-bar').css('position', 'static');
}
});
});
}
if ($('#right-bar .con').find('b').unbind()[0]) {
myHammer = new Hammer($('#right-bar .con').find('b').unbind()[0]);
myHammer.on('tap', function(e) {
var index = $(this).index();
if ($('.bar-' + index).size() > 0) {
document.body.scrollTop = parseInt($('.bar-' + index)[0].offsetTop) - parseInt(brandSwipe - 1);
}
});
}
function searchResult(type) {
var keyword = $('#keyword').val(),
gender = $('#gender').val();
$.get('/brands/search', {
keyword: keyword,
gender: gender,
type: type
}, function(html) {
$('.search-result').html(html);
});
}
$('#keyword').on('keyup', function() {
searchResult(0);
}).on('keydown', function() {
$(this).closest('.search-box').css('width', '11.25rem');
$('.search-action').show();
}).on('blur', function() {
$(this).closest('.search-box').css('width', '12.5rem');
$('.search-action').hide();
});
$('#search-btn').on('tap', function() {
searchResult(1);
});
$('.clear-text').on('tap', function() {
$('#keyword').val('').trigger('input');
});
$('form.search-box').on('submit', function() {
return false;
});
$('.clear-history').on('tap', function() {
// setcookie('h_brands', '', {
// expire: -1,
// path: '/',
// domain: '.m.yohobuy.com'
// });
$('#history-keyword').remove();
$(this).hide();
});