Showing
4 changed files
with
59 additions
and
23 deletions
1 | {{# nav}} | 1 | {{# nav}} |
2 | -<nav class="outlet-nav"> | 2 | +<nav class="outlet-nav" id="index_nav"> |
3 | <ul> | 3 | <ul> |
4 | {{#each data}} | 4 | {{#each data}} |
5 | <li><a href="{{url}}">{{name}}</a></li> | 5 | <li><a href="{{url}}">{{name}}</a></li> |
6 | {{/each}} | 6 | {{/each}} |
7 | - <li><a href="outlet/willBeEnd">即将结束</a></li> | ||
8 | - <li><a href="outlet/willBeCome">上线预告</a></li> | 7 | + <li><a href="outlet/willStart">即将结束</a></li> |
8 | + <li><a href="outlet/willEnd">即将开始</a></li> | ||
9 | </ul> | 9 | </ul> |
10 | </nav> | 10 | </nav> |
11 | {{/nav}} | 11 | {{/nav}} |
@@ -4,14 +4,15 @@ var $ = require('yoho-jquery'), | @@ -4,14 +4,15 @@ var $ = require('yoho-jquery'), | ||
4 | 4 | ||
5 | var search = require('./sale/search'); | 5 | var search = require('./sale/search'); |
6 | 6 | ||
7 | -search.setOutLoad(false); | ||
8 | 7 | ||
9 | // var nav = require('./outlet/nav'); | 8 | // var nav = require('./outlet/nav'); |
9 | +var iscroll = require('./outlet/nav'); | ||
10 | 10 | ||
11 | require('./sale/search'); | 11 | require('./sale/search'); |
12 | 12 | ||
13 | lazyLoad($('img.lazy')); | 13 | lazyLoad($('img.lazy')); |
14 | 14 | ||
15 | +search.setOutLoad(false); | ||
15 | // nav({ | 16 | // nav({ |
16 | // navClass: '.outlet-nav' | 17 | // navClass: '.outlet-nav' |
17 | // }) | 18 | // }) |
@@ -51,7 +52,7 @@ $('.outlet-category-nav a').on('click', function(e) { | @@ -51,7 +52,7 @@ $('.outlet-category-nav a').on('click', function(e) { | ||
51 | }, query); | 52 | }, query); |
52 | }); | 53 | }); |
53 | 54 | ||
54 | -$('.outlet-category-nav a').eq(0).trigger('click'); | 55 | + // $('.outlet-category-nav a').eq(0).trigger('click'); |
55 | 56 | ||
56 | if (('.outlet-page').length > 0) { | 57 | if (('.outlet-page').length > 0) { |
57 | $('.more-activity').on('click', function() { | 58 | $('.more-activity').on('click', function() { |
@@ -71,3 +72,12 @@ if (('.outlet-page').length > 0) { | @@ -71,3 +72,12 @@ if (('.outlet-page').length > 0) { | ||
71 | 72 | ||
72 | 73 | ||
73 | } | 74 | } |
75 | + | ||
76 | +// 导航滚动 | ||
77 | +iscroll({ | ||
78 | + el: '#index_nav' | ||
79 | +}).goto($('#index_nav').find('.active').index()); | ||
80 | + | ||
81 | +iscroll({ | ||
82 | + el: '#list-nav' | ||
83 | +}).goto(0); |
1 | var $ = require('yoho-jquery'), | 1 | var $ = require('yoho-jquery'), |
2 | IScroll = require('yoho-iscroll'); | 2 | IScroll = require('yoho-iscroll'); |
3 | 3 | ||
4 | -var defaultOpt = { | ||
5 | - navClass: '.outlet-nav' | ||
6 | -}; | ||
7 | - | ||
8 | // nav 滚动 | 4 | // nav 滚动 |
9 | function initNavScroll(opt) { | 5 | function initNavScroll(opt) { |
10 | var $navBox, | 6 | var $navBox, |
11 | - iScroll; | ||
12 | - | ||
13 | - $.extend(opt || {}, defaultOpt); | 7 | + iScroll, |
8 | + _default = { | ||
9 | + el: '.outlet-nav' | ||
10 | + }, | ||
11 | + options; | ||
14 | 12 | ||
15 | - $navBox = $(opt.navClass); | 13 | + options = $.extend({}, _default, opt); |
14 | + $navBox = $(options.el); | ||
16 | 15 | ||
17 | - function scroll(ele) { | ||
18 | - var offset; | ||
19 | - | ||
20 | - ele = ele || $navBox.find('li').eq(0)[0]; | ||
21 | - offset = -($navBox.find('ul').width() - 20) / 2; | 16 | + function scroll(index) { |
17 | + var $ele; | ||
22 | 18 | ||
19 | + $ele = $navBox.find('li').eq(index); | ||
20 | + if ($ele.length > 0) { | ||
23 | setTimeout(function() { | 21 | setTimeout(function() { |
24 | - iScroll.scrollToElement(ele, 400, offset); | 22 | + iScroll.scrollToElement($ele[0], 400); |
25 | }, 1); | 23 | }, 1); |
26 | } | 24 | } |
25 | + } | ||
27 | 26 | ||
28 | - $.each($navBox, function(index) { | ||
29 | - iScroll = new IScroll($navBox[index], { | 27 | + iScroll = new IScroll($navBox[0], { |
30 | scrollX: true, | 28 | scrollX: true, |
31 | scrollY: false | 29 | scrollY: false |
32 | }); | 30 | }); |
33 | - }); | ||
34 | 31 | ||
35 | - scroll($navBox.find('.active')[0]); | 32 | + return { |
33 | + goto: scroll | ||
34 | + }; | ||
36 | } | 35 | } |
37 | 36 | ||
37 | +// 获取url中的参数 | ||
38 | +function getUrlParam(name) { | ||
39 | + var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'); // 构造一个含有目标参数的正则表达式对象 | ||
40 | + var r = window.location.search.substr(1).match(reg); // 匹配目标参数 | ||
41 | + | ||
42 | + // 返回参数值 | ||
43 | + if (r !== null) { | ||
44 | + return decodeURIComponent(r[2]); | ||
45 | + } else { | ||
46 | + return null; | ||
47 | + } | ||
48 | +} | ||
49 | + | ||
50 | +// 选中顶部导航 | ||
51 | +function activeNav() { | ||
52 | + var $nav = $('#index_nav'); | ||
53 | + var index = getUrlParam('yh_channel'); | ||
54 | + | ||
55 | + if (index === null) { | ||
56 | + index = 0; | ||
57 | + } | ||
58 | + $nav.find('li').eq(index).addClass('active').siblings().removeClass('active'); | ||
59 | +} | ||
60 | + | ||
61 | + | ||
62 | +activeNav(); | ||
63 | + | ||
38 | module.exports = initNavScroll; | 64 | module.exports = initNavScroll; |
39 | 65 |
-
Please register or login to post a comment