Authored by 梁志锋

use requestAnimationFrame for window scroll event

... ... @@ -45,7 +45,7 @@ $fixTitleBar.css({
minBrandListTop = brandSwipe + $('.hot-brand').outerHeight() + $('.banner-top').outerHeight();
$brandList.last().append($fixTitleBar);
$(window).scroll(function() {
function scrollHandler() {
var scrTop = $(window).scrollTop();
if ($brandList.eq(0).offset().top < minBrandListTop) {
... ... @@ -62,6 +62,10 @@ $(window).scroll(function() {
}
});
}
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
function changeBackground() {
... ...
... ... @@ -107,12 +107,16 @@ $nav.on('touchend touchcancel', function(e) {
}
});
$(document).scroll(function() {
function scrollHandler() {
var $c = $infos.not('.hide');
if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $c.height()) {
loadMore($c, state[curType]);
}
}
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
$nav.on('touchstart', function(e) {
... ...
... ... @@ -40,8 +40,12 @@ if ($tag.length > 0) {
});
}
$(document).scroll(function() {
function scrollHandler() {
if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $infos.height()) {
loadMore($infos, setting);
}
}
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
\ No newline at end of file
... ...
... ... @@ -138,8 +138,12 @@ $('.maybe-like p').on('touchstart', function (e) {
});
//srcoll to load more
$(window).scroll(function () {
function scrollHandler() {
if ($(window).scrollTop() + winH >= $(document).height() - 50) {
search();
}
}
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
\ No newline at end of file
... ...
... ... @@ -91,9 +91,8 @@ var updateLayerPosition = (function() {
};
})();
$win.scroll(function() {
updateLayerPosition();
$(window).scroll(function() {
window.requestAnimationFrame(updateLayerPosition);
});
$doc.on('ready', updateLayerPosition);
... ...
... ... @@ -206,9 +206,8 @@ favContentHammer.on('tap', function(e) {
});
});
// 上拉加载更多
$(document).scroll(function() {
function scrollHandler() {
if ($(window).scrollTop() + winH >= $(document).height() - footerH) {
if (brandTab) {
... ... @@ -231,4 +230,8 @@ $(document).scroll(function() {
}
}
}
}
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
\ No newline at end of file
... ...
... ... @@ -18,13 +18,17 @@ var setting = {
end: false
};
function scrollHandler() {
if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $infoList.height()) {
loadMore($infoList, setting, '/home/myguang');
}
}
//对于有逛收藏的页面进行事件处理
if ($infoList.length > 0) {
info.initInfosEvt($infoList);
$(window).scroll(function() {
if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $infoList.height()) {
loadMore($infoList, setting, '/home/myguang');
}
window.requestAnimationFrame(scrollHandler);
});
}
\ No newline at end of file
... ...
... ... @@ -167,7 +167,7 @@ orderHammer.on('tap', function(e) {
}
});
$(window).scroll(function() {
function scrollHandler() {
if (order.end === false && $(window).scrollTop() + winH >
$(document).height() - 0.25 * $orderContainer.height()) {
... ... @@ -176,6 +176,10 @@ $(window).scroll(function() {
noLoadingMask: true
});
}
}
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
//初始化请求第一页数据
... ...
... ... @@ -362,13 +362,17 @@ $listNav.on('touchend touchcancel', function(e) {
}
});
$(window).scroll(function() {
function scrollHandler() {
//当scroll到1/4$goodsContainer高度后继续请求下一页数据
if ($(window).scrollTop() + winH >
$(document).height() - 0.25 * $goodsContainer.height()) {
search();
}
}
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
if ($brandHeader.length > 0) {
... ...
... ... @@ -351,7 +351,7 @@ $listNav.on('touchend touchcancel', function(e) {
e.stopPropagation();
});
$(window).scroll(function() {
function scrollHandler() {
//当scroll到1/4$goodsContainer高度后继续请求下一页数据
if ($(window).scrollTop() + winH >
... ... @@ -360,6 +360,10 @@ $(window).scroll(function() {
search();
}
}
}
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
//初始请求最新第一页数据
... ...
... ... @@ -53,7 +53,8 @@ function hotrank(page, sort, tabId, notab) {
});
}
$(window).scroll(function () {
function scrollHandler() {
if (page === 2) {
return;
}
... ... @@ -63,8 +64,12 @@ $(window).scroll(function () {
page = 2;
notab = 1;
hotrank(page, sort, id, notab);
}
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
hotrank(page, sort, id, notab);
hotnav = new Hammer(document.getElementById('hotRank'));
hotnav.on('tap', function (e) {
... ...
... ... @@ -359,7 +359,8 @@ $listNav.on('touchend touchcancel', function(e) {
e.stopPropagation();
});
$(window).scroll(function() {
function scrollHandler() {
//当scroll到1/4$goodsContainer高度后继续请求下一页数据
if ($(window).scrollTop() + winH >
... ... @@ -368,6 +369,10 @@ $(window).scroll(function() {
search();
}
}
}
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
//初始请求最新第一页数据
... ...