以下代码实现判断页面的滚动条的滚动方向;
var sign = 80;//定义默认的向上滚与向下滚的边界 window.onscroll = window.onresize = function(){ var oScrollTop=$(window).scrollTop(); if ( oScrollTop > 80) { //write your code } if ( oScrollTop < 80) { //write your code }
if ( oScrollTop > sign) { sign = oScrollTop;//更新scrollTop //console.log('向下'); } if ( oScrollTop< sign) { sign = oScrollTop//更新scrollTop //console.log('向上'); } }