jquery获取元素到屏幕四周可视距离的方法

作者:猪哥 2018-09-07

实例如下:

$(window).height();//是文档窗口高度
$("div").offset().top//是标签距离顶部高度(没有到下面的距离,比如$("div").offset().down)
$("div").offset().left//是标签距离右边高度(没有到下面的距离,比如$("div").offset().right)

$(document).scrollTop();//是滚动条高度
$("div").height();//是标签高度

你要的高度+$("div").height()+[$("div").offset().top-$(document).scrollTop()]=$(window).height();

经过简单的数学变换即可得到你要的值了!

相关文章

精彩推荐