Showing
1 changed file
with
19 additions
and
18 deletions
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | * @Author: Targaryen | 2 | * @Author: Targaryen |
3 | * @Date: 2017-03-24 13:43:55 | 3 | * @Date: 2017-03-24 13:43:55 |
4 | * @Last Modified by: Targaryen | 4 | * @Last Modified by: Targaryen |
5 | - * @Last Modified time: 2017-03-24 16:54:26 | 5 | + * @Last Modified time: 2017-03-24 17:57:30 |
6 | */ | 6 | */ |
7 | 7 | ||
8 | /** ***************************** | 8 | /** ***************************** |
@@ -26,37 +26,28 @@ const shopId = $('#shopId').val(); | @@ -26,37 +26,28 @@ const shopId = $('#shopId').val(); | ||
26 | let navInfo = { | 26 | let navInfo = { |
27 | price: { | 27 | price: { |
28 | order: 1, | 28 | order: 1, |
29 | - reload: true, | ||
30 | - page: 0, | ||
31 | end: false | 29 | end: false |
32 | }, | 30 | }, |
33 | discount: { | 31 | discount: { |
34 | order: 1, | 32 | order: 1, |
35 | - reload: true, | ||
36 | - page: 0, | ||
37 | end: false | 33 | end: false |
38 | }, | 34 | }, |
39 | default: { | 35 | default: { |
40 | order: 0, | 36 | order: 0, |
41 | - reload: true, | ||
42 | - page: 0, | ||
43 | end: false, | 37 | end: false, |
44 | type: 'default' | 38 | type: 'default' |
45 | }, | 39 | }, |
46 | new: { | 40 | new: { |
47 | order: 0, | 41 | order: 0, |
48 | - reload: true, | ||
49 | - page: 0, | ||
50 | end: false | 42 | end: false |
51 | }, | 43 | }, |
52 | sale: { | 44 | sale: { |
53 | order: 0, | 45 | order: 0, |
54 | - reload: true, | ||
55 | - page: 0, | ||
56 | end: false | 46 | end: false |
57 | } | 47 | } |
58 | }; | 48 | }; |
59 | 49 | ||
50 | +let beforeScroll = document.body.scrollTop; // 滚动前位置记录 | ||
60 | let navType = 'default'; // 目前激活的导航页面 | 51 | let navType = 'default'; // 目前激活的导航页面 |
61 | let defaultOpt = Object.assign({}, navInfo.default, {shop_id: shopId}); // 默认参数 | 52 | let defaultOpt = Object.assign({}, navInfo.default, {shop_id: shopId}); // 默认参数 |
62 | let onSearching = false; // 是否正在搜索 | 53 | let onSearching = false; // 是否正在搜索 |
@@ -82,7 +73,7 @@ const handleChoseFilter = function() { | @@ -82,7 +73,7 @@ const handleChoseFilter = function() { | ||
82 | const getGoodsList = function() { | 73 | const getGoodsList = function() { |
83 | handleChoseFilter(); | 74 | handleChoseFilter(); |
84 | 75 | ||
85 | - if (isScrollLoad && !onSearching) { | 76 | + if (!onSearching) { |
86 | Object.assign(defaultOpt, { | 77 | Object.assign(defaultOpt, { |
87 | page: page++ | 78 | page: page++ |
88 | }); | 79 | }); |
@@ -197,6 +188,8 @@ $listNav.bind('contextmenu', function() { | @@ -197,6 +188,8 @@ $listNav.bind('contextmenu', function() { | ||
197 | }); | 188 | }); |
198 | 189 | ||
199 | $listNav.on('touchend touchcancel', function(e) { | 190 | $listNav.on('touchend touchcancel', function(e) { |
191 | + page = 0; | ||
192 | + beforeScroll = $(window).scrollTop(); | ||
200 | isScrollLoad = false; | 193 | isScrollLoad = false; |
201 | 194 | ||
202 | let $this = $(e.target).closest('li'); // 被点击的 Tab | 195 | let $this = $(e.target).closest('li'); // 被点击的 Tab |
@@ -248,7 +241,6 @@ $listNav.on('touchend touchcancel', function(e) { | @@ -248,7 +241,6 @@ $listNav.on('touchend touchcancel', function(e) { | ||
248 | // 价格或折扣切换排序状态 | 241 | // 价格或折扣切换排序状态 |
249 | $this.find('.icon > .iconfont').toggleClass('cur'); | 242 | $this.find('.icon > .iconfont').toggleClass('cur'); |
250 | $pre = $this; // 更新 pre 为当前项 | 243 | $pre = $this; // 更新 pre 为当前项 |
251 | - nav.reload = true; // 排序改变,标记需要重新获取数据 | ||
252 | nav.order = nav.order === 0 ? 1 : 0; // 切换排序 | 244 | nav.order = nav.order === 0 ? 1 : 0; // 切换排序 |
253 | } | 245 | } |
254 | } else { | 246 | } else { |
@@ -270,15 +262,24 @@ $listNav.on('touchend touchcancel', function(e) { | @@ -270,15 +262,24 @@ $listNav.on('touchend touchcancel', function(e) { | ||
270 | defaultOpt.type = navType; | 262 | defaultOpt.type = navType; |
271 | Object.assign(defaultOpt, nav); | 263 | Object.assign(defaultOpt, nav); |
272 | 264 | ||
273 | - if (nav.reload) { | ||
274 | - getGoodsList(); | ||
275 | - } | 265 | + getGoodsList(); |
276 | } | 266 | } |
277 | }); | 267 | }); |
278 | 268 | ||
279 | -// srcoll to load more | 269 | +/** |
270 | + * 滚动加载 | ||
271 | + */ | ||
280 | $(window).scroll(function() { | 272 | $(window).scroll(function() { |
281 | - window.requestAnimationFrame(scrollHandler); | 273 | + setTimeout(function() { |
274 | + let afterScroll = document.body.scrollTop; | ||
275 | + | ||
276 | + if (afterScroll - beforeScroll > 0) { | ||
277 | + window.requestAnimationFrame(scrollHandler); | ||
278 | + beforeScroll = afterScroll; | ||
279 | + } else { | ||
280 | + return false; | ||
281 | + } | ||
282 | + }, 5); | ||
282 | }); | 283 | }); |
283 | 284 | ||
284 | module.exports = { | 285 | module.exports = { |
-
Please register or login to post a comment