Authored by 梁志锋

use requestAnimationFrame for window scroll event

... ... @@ -133,7 +133,7 @@ function search() {
});
}
$('.maybe-like p').on('touchstart', function (e) {
$('.maybe-like p').on('touchstart', function(e) {
search();
});
... ...
... ... @@ -68,28 +68,33 @@ $channelLink.on('touchstart', function() {
borderColor: '#fff'
});
});
var updateLayerPosition = (function() {
var init = false;
return function() {
var winHeight = window.innerHeight;
var bodyHeight = $doc.height();
var scrollTopPosition = $win.scrollTop();
var layerHeight = $appFloatLayer.height();
var layerPaddingTop = parseInt($appFloatLayer.css('padding-top'));
var layerPaddingBottom = parseInt($appFloatLayer.css('padding-bottom'));
var newPosition;
if(init){
newPosition = bodyHeight - winHeight- scrollTopPosition;
}else{
init = true;
newPosition = bodyHeight - winHeight - scrollTopPosition + layerHeight + layerPaddingTop + layerPaddingBottom;
}
$appFloatLayer.css({
'position': 'relative',
'bottom': newPosition + 'px'
});
};
})();
function updateLayerPosition() {
var init = false;
return function() {
var winHeight = window.innerHeight;
var bodyHeight = $doc.height();
var scrollTopPosition = $win.scrollTop();
var layerHeight = $appFloatLayer.height();
var layerPaddingTop = parseInt($appFloatLayer.css('padding-top'));
var layerPaddingBottom = parseInt($appFloatLayer.css('padding-bottom'));
var newPosition;
if (init) {
newPosition = bodyHeight - winHeight - scrollTopPosition;
} else {
init = true;
newPosition = bodyHeight - winHeight - scrollTopPosition +
layerHeight + layerPaddingTop + layerPaddingBottom;
}
$appFloatLayer.css({
position: 'relative',
bottom: newPosition + 'px'
});
};
}
$(window).scroll(function() {
window.requestAnimationFrame(updateLayerPosition);
... ...
... ... @@ -347,7 +347,6 @@ $listNav.on('touchend touchcancel', function(e) {
search();
}
}
e.stopPropagation();
});
... ...
... ... @@ -72,7 +72,7 @@ $(window).scroll(function() {
hotrank(page, sort, id, notab);
hotnav = new Hammer(document.getElementById('hotRank'));
hotnav.on('tap', function (e) {
hotnav.on('tap', function(e) {
var ev = ev || window.event;
var target = ev.target || ev.srcElement;
... ...