nav.js
774 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
var $ = require('yoho-jquery'),
IScroll = require('yoho-iscroll');
var defaultOpt = {
navClass: '.outlet-nav'
};
// nav 滚动
function initNavScroll(opt) {
var $navBox,
iScroll;
$.extend(opt || {}, defaultOpt);
$navBox = $(opt.navClass);
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);
}
$.each($navBox, function(index) {
iScroll = new IScroll($navBox[index], {
scrollX: true,
scrollY: false
});
});
scroll($navBox.find('.active')[0]);
}
module.exports = initNavScroll;