jquery 判断滚动方向 向上还是向下
scroll(function(direction) { console.log(direction) });
function scroll( fn ) {
var $window = $(window),
beforeScrollTop = $window.scrollTop(),
fn = fn || function() {};
$window.scroll(function() {
var afterScrollTop = $window.scrollTop(),
delta = afterScrollTop - beforeScrollTop;
if( delta === 0 ) return false;
fn( delta > 0 ? "down" : "up" );
beforeScrollTop = afterScrollTop;
});
}
(。・v・。)
喜欢这篇文章吗?欢迎分享到你的微博、QQ群,并关注我们的微博,谢谢支持。