jquery如何获取页面当前屏幕顶部位置?

标签 jquery

jquery如何获取页面当前屏幕顶部位置?

如果我将鼠标滚轮滚动到页面的某个部分,如何获取页面当前的顶部位置?

我想单击页面中的一个元素,然后打开一个顶部位于当前屏幕顶部的 div。

所以只需将当前屏幕顶部位置设置为:

$('#content').css('top','current position');

#content
{
position:absolute;
left:100px;
}

最佳答案

使用它来获取页面滚动位置。

var screenTop = $(document).scrollTop();

$('#content').css('top', screenTop);

关于jquery如何获取页面当前屏幕顶部位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7019353/

相关文章:

javascript - jQuery 图像选择器 - 以编程方式选择多个图像

javascript - 为什么我无法通过 jQuery/JS 字符串插值找到 html 元素?

javascript - JQuery - 单击时将背景图像替换为另一个背景图像

javascript - 防止滚动冒泡

javascript - html2canvas() 中的屏幕截图是在哪里制作的?

php - 如何将菜单置于内容之上?

javascript - JQuery 可排序 : Can I treat two rows as one row when dragging to another position?

php - 我如何在ajax请求中传递使用fileopen对话框加载的文件

javascript - 当我使用 equalHeights jQuery 插件时,IE8 返回 “object doesn' t support this property or method”

javascript - ajax页面刷新表单提交成功