Authored by 梁志锋

use requestAnimationFrame for scroll event

@@ -45,7 +45,7 @@ $fixTitleBar.css({ @@ -45,7 +45,7 @@ $fixTitleBar.css({
45 minBrandListTop = brandSwipe + $('.hot-brand').outerHeight() + $('.banner-top').outerHeight(); 45 minBrandListTop = brandSwipe + $('.hot-brand').outerHeight() + $('.banner-top').outerHeight();
46 $brandList.last().append($fixTitleBar); 46 $brandList.last().append($fixTitleBar);
47 47
48 -$(window).scroll(function() { 48 +function scrollHandler() {
49 var scrTop = $(window).scrollTop(); 49 var scrTop = $(window).scrollTop();
50 50
51 if ($brandList.eq(0).offset().top < minBrandListTop) { 51 if ($brandList.eq(0).offset().top < minBrandListTop) {
@@ -62,8 +62,14 @@ $(window).scroll(function() { @@ -62,8 +62,14 @@ $(window).scroll(function() {
62 } 62 }
63 63
64 }); 64 });
  65 +}
  66 +
  67 +//srcoll to load more
  68 +$(window).scroll(function() {
  69 + window.requestAnimationFrame(scrollHandler);
65 }); 70 });
66 71
  72 +
67 function changeBackground() { 73 function changeBackground() {
68 var $brandList = $('.brand-list').find('p'); 74 var $brandList = $('.brand-list').find('p');
69 75
@@ -107,12 +107,17 @@ $nav.on('touchend touchcancel', function(e) { @@ -107,12 +107,17 @@ $nav.on('touchend touchcancel', function(e) {
107 } 107 }
108 }); 108 });
109 109
110 -$(document).scroll(function() { 110 +function scrollHandler() {
111 var $c = $infos.not('.hide'); 111 var $c = $infos.not('.hide');
112 112
113 if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $c.height()) { 113 if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $c.height()) {
114 loadMore($c, state[curType]); 114 loadMore($c, state[curType]);
115 } 115 }
  116 +}
  117 +
  118 +//srcoll to load more
  119 +$(document).scroll(function() {
  120 + window.requestAnimationFrame(scrollHandler);
116 }); 121 });
117 122
118 $nav.on('touchstart', function(e) { 123 $nav.on('touchstart', function(e) {
@@ -40,8 +40,13 @@ if ($tag.length > 0) { @@ -40,8 +40,13 @@ if ($tag.length > 0) {
40 }); 40 });
41 } 41 }
42 42
43 -$(document).scroll(function() { 43 +function scrollHandler() {
44 if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $infos.height()) { 44 if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $infos.height()) {
45 loadMore($infos, setting); 45 loadMore($infos, setting);
46 } 46 }
  47 +}
  48 +
  49 +//srcoll to load more
  50 +$(window).scroll(function() {
  51 + window.requestAnimationFrame(scrollHandler);
47 }); 52 });
@@ -137,9 +137,13 @@ $('.maybe-like p').on('touchstart', function (e) { @@ -137,9 +137,13 @@ $('.maybe-like p').on('touchstart', function (e) {
137 search(); 137 search();
138 }); 138 });
139 139
140 -//srcoll to load more  
141 -$(window).scroll(function () { 140 +function scrollHandler() {
142 if ($(window).scrollTop() + winH >= $(document).height() - 50) { 141 if ($(window).scrollTop() + winH >= $(document).height() - 50) {
143 search(); 142 search();
144 } 143 }
  144 +}
  145 +
  146 +//srcoll to load more
  147 +$(window).scroll(function() {
  148 + window.requestAnimationFrame(scrollHandler);
145 }); 149 });
@@ -206,14 +206,11 @@ favContentHammer.on('tap', function(e) { @@ -206,14 +206,11 @@ favContentHammer.on('tap', function(e) {
206 }); 206 });
207 }); 207 });
208 208
209 -// 上拉加载更多  
210 -$(document).scroll(function() { 209 +function scrollHandler() {
211 210
212 if ($(window).scrollTop() + winH >= $(document).height() - footerH) { 211 if ($(window).scrollTop() + winH >= $(document).height() - footerH) {
213 212
214 if (brandTab) { 213 if (brandTab) {
215 - console.log(1);  
216 -  
217 $brandLoadMore.filter('.hide').removeClass('hide'); 214 $brandLoadMore.filter('.hide').removeClass('hide');
218 215
219 if (!brandLockId) { 216 if (!brandLockId) {
@@ -231,4 +228,9 @@ $(document).scroll(function() { @@ -231,4 +228,9 @@ $(document).scroll(function() {
231 } 228 }
232 } 229 }
233 } 230 }
  231 +}
  232 +
  233 +//srcoll to load more
  234 +$(window).scroll(function() {
  235 + window.requestAnimationFrame(scrollHandler);
234 }); 236 });
@@ -18,13 +18,21 @@ var setting = { @@ -18,13 +18,21 @@ var setting = {
18 end: false 18 end: false
19 }; 19 };
20 20
  21 +function scrollHandler() {
  22 + if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $infoList.height()) {
  23 + loadMore($infoList, setting, '/home/myguang');
  24 + }
  25 +}
  26 +
21 //对于有逛收藏的页面进行事件处理 27 //对于有逛收藏的页面进行事件处理
22 if ($infoList.length > 0) { 28 if ($infoList.length > 0) {
23 info.initInfosEvt($infoList); 29 info.initInfosEvt($infoList);
24 30
  31 + //srcoll to load more
25 $(window).scroll(function() { 32 $(window).scroll(function() {
26 - if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $infoList.height()) {  
27 - loadMore($infoList, setting, '/home/myguang');  
28 - } 33 + window.requestAnimationFrame(scrollHandler);
29 }); 34 });
30 } 35 }
  36 +
  37 +
  38 +
@@ -167,7 +167,7 @@ orderHammer.on('tap', function(e) { @@ -167,7 +167,7 @@ orderHammer.on('tap', function(e) {
167 } 167 }
168 }); 168 });
169 169
170 -$(window).scroll(function() { 170 +function scrollHandler() {
171 if (order.end === false && $(window).scrollTop() + winH > 171 if (order.end === false && $(window).scrollTop() + winH >
172 $(document).height() - 0.25 * $orderContainer.height()) { 172 $(document).height() - 0.25 * $orderContainer.height()) {
173 173
@@ -176,6 +176,11 @@ $(window).scroll(function() { @@ -176,6 +176,11 @@ $(window).scroll(function() {
176 noLoadingMask: true 176 noLoadingMask: true
177 }); 177 });
178 } 178 }
  179 +}
  180 +
  181 +//srcoll to load more
  182 +$(window).scroll(function() {
  183 + window.requestAnimationFrame(scrollHandler);
179 }); 184 });
180 185
181 //初始化请求第一页数据 186 //初始化请求第一页数据
@@ -100,4 +100,3 @@ function scrollHandler() { @@ -100,4 +100,3 @@ function scrollHandler() {
100 $(window).scroll(function() { 100 $(window).scroll(function() {
101 window.requestAnimationFrame(scrollHandler); 101 window.requestAnimationFrame(scrollHandler);
102 }); 102 });
103 -  
@@ -362,13 +362,18 @@ $listNav.on('touchend touchcancel', function(e) { @@ -362,13 +362,18 @@ $listNav.on('touchend touchcancel', function(e) {
362 } 362 }
363 }); 363 });
364 364
365 -$(window).scroll(function() { 365 +function scrollHandler() {
366 366
367 //当scroll到1/4$goodsContainer高度后继续请求下一页数据 367 //当scroll到1/4$goodsContainer高度后继续请求下一页数据
368 if ($(window).scrollTop() + winH > 368 if ($(window).scrollTop() + winH >
369 $(document).height() - 0.25 * $goodsContainer.height()) { 369 $(document).height() - 0.25 * $goodsContainer.height()) {
370 search(); 370 search();
371 } 371 }
  372 +}
  373 +
  374 +//srcoll to load more
  375 +$(window).scroll(function() {
  376 + window.requestAnimationFrame(scrollHandler);
372 }); 377 });
373 378
374 if ($brandHeader.length > 0) { 379 if ($brandHeader.length > 0) {
@@ -351,7 +351,7 @@ $listNav.on('touchend touchcancel', function(e) { @@ -351,7 +351,7 @@ $listNav.on('touchend touchcancel', function(e) {
351 e.stopPropagation(); 351 e.stopPropagation();
352 }); 352 });
353 353
354 -$(window).scroll(function() { 354 +function scrollHandler() {
355 355
356 //当scroll到1/4$goodsContainer高度后继续请求下一页数据 356 //当scroll到1/4$goodsContainer高度后继续请求下一页数据
357 if ($(window).scrollTop() + winH > 357 if ($(window).scrollTop() + winH >
@@ -360,6 +360,11 @@ $(window).scroll(function() { @@ -360,6 +360,11 @@ $(window).scroll(function() {
360 search(); 360 search();
361 } 361 }
362 } 362 }
  363 +}
  364 +
  365 +//srcoll to load more
  366 +$(window).scroll(function() {
  367 + window.requestAnimationFrame(scrollHandler);
363 }); 368 });
364 369
365 //初始请求最新第一页数据 370 //初始请求最新第一页数据
@@ -53,7 +53,7 @@ function hotrank(page, sort, tabId, notab) { @@ -53,7 +53,7 @@ function hotrank(page, sort, tabId, notab) {
53 }); 53 });
54 } 54 }
55 55
56 -$(window).scroll(function () { 56 +function scrollHandler() {
57 if (page === 2) { 57 if (page === 2) {
58 return; 58 return;
59 } 59 }
@@ -63,8 +63,13 @@ $(window).scroll(function () { @@ -63,8 +63,13 @@ $(window).scroll(function () {
63 page = 2; 63 page = 2;
64 notab = 1; 64 notab = 1;
65 hotrank(page, sort, id, notab); 65 hotrank(page, sort, id, notab);
  66 +}
66 67
  68 +//srcoll to load more
  69 +$(window).scroll(function() {
  70 + window.requestAnimationFrame(scrollHandler);
67 }); 71 });
  72 +
68 hotrank(page, sort, id, notab); 73 hotrank(page, sort, id, notab);
69 hotnav = new Hammer(document.getElementById('hotRank')); 74 hotnav = new Hammer(document.getElementById('hotRank'));
70 hotnav.on('tap', function (e) { 75 hotnav.on('tap', function (e) {
@@ -359,7 +359,7 @@ $listNav.on('touchend touchcancel', function(e) { @@ -359,7 +359,7 @@ $listNav.on('touchend touchcancel', function(e) {
359 e.stopPropagation(); 359 e.stopPropagation();
360 }); 360 });
361 361
362 -$(window).scroll(function() { 362 +function scrollHandler() {
363 363
364 //当scroll到1/4$goodsContainer高度后继续请求下一页数据 364 //当scroll到1/4$goodsContainer高度后继续请求下一页数据
365 if ($(window).scrollTop() + winH > 365 if ($(window).scrollTop() + winH >
@@ -368,6 +368,11 @@ $(window).scroll(function() { @@ -368,6 +368,11 @@ $(window).scroll(function() {
368 search(); 368 search();
369 } 369 }
370 } 370 }
  371 +}
  372 +
  373 +//srcoll to load more
  374 +$(window).scroll(function() {
  375 + window.requestAnimationFrame(scrollHandler);
371 }); 376 });
372 377
373 //初始请求最新第一页数据 378 //初始请求最新第一页数据