jquery如何获取页面当前的屏幕顶部位置?
如果我将鼠标滚轮滚动到页面的某一部分,如何获得页面当前的顶部位置?
我想点击我的页面中的一个元素,然后打开一个顶部是当前屏幕顶部的div。
因此,只需将当前屏幕顶部位置设置为:
$('#content').css('top','current position');和
#content
{
position:absolute;
left:100px;
}发布于 2011-08-11 07:57:38
var top = $('html').offset().top;应该做这件事。
编辑:这是$(document).scrollTop()的负数
发布于 2011-08-11 07:57:50
使用此选项可获取页面滚动位置。
var screenTop = $(document).scrollTop();
$('#content').css('top', screenTop);https://stackoverflow.com/questions/7019353
复制相似问题