home.js
930 Bytes
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
var $ = require('yoho-jquery'),
IScroll = require('yoho-iscroll'),
lazyLoad = require('yoho-jquery-lazyload');
lazyLoad($('img.lazy'));
// nav 滚动
function initNavScroll() {
var $navBox = $('.outlet-nav'),
$lis = $navBox.find('li'),
iScroll;
function scroll(ele) {
var offset;
ele = ele || $navBox.find('li').eq(0)[0];
offset = -($navBox.find('ul').width() - 20) / 2;
setTimeout(function() {
iScroll.scrollToElement(ele, 400, offset);
}, 1);
}
iScroll = new IScroll($navBox[0], {
scrollX: true,
scrollY: false
});
$navBox.on('click', 'li', function() {
var $this = $(this); // eslint-disable-line
var i = $this.index();
$lis.eq(i).addClass('active').siblings().removeClass('active');
scroll($this[0]);
});
scroll($navBox.find('.active')[0]);
}
initNavScroll();