js判断元素是否出现在可视区内

$(".footer").offset().top//元素距离网页顶部的距离

$(window).scrollTop()//网页卷出的高度

$(window).height()//浏览器可视窗口的高度

window.onscroll = function () {

let top = $(".footer").offset().top;

let dw_height = ($(window).scrollTop() + $(window).height()) - top <= 0 ? 0 : ($(window).scrollTop() + $(window).height()) - top;

if (top >= $(window).scrollTop() && top < ($(window).scrollTop() + $(window).height())) {

$(".drag").css("bottom", dw_height);

} else {

$(".drag").css("bottom", 0);

扫描二维码关注公众号,回复: 3048514 查看本文章

}

}

猜你喜欢

转载自blog.csdn.net/zfeng816/article/details/82216770