监听内容是否在可视区

Posted on 2016-10-19 14:36  发飙的木鱼  阅读(110)  评论(0)    收藏  举报

判断内容是否在可视区
$(window).scroll(function(){
var itemHeight = parseInt($(".historyUl").outerHeight(true));//内容区域的高度
var vh = parseInt($(window).height());//浏览器可视区域的高度
var yh = parseInt($(window).scrollTop());//偏移量
if(!(yh>($(".historyUl").offset().top + itemHeight)||yh < ($(".historyUl").offset().top - vh))){
console.log(1)
}else{
console.log(2)
}
})