jquery - 为什么 offset() 依赖于滚动
问题描述
根据文档:
offset() 方法设置或返回所选元素相对于文档的偏移坐标。
所以offset()
不应该依赖于滚动中的位置。
但是,在我的代码中:我的 html 格式为:
...
<div class="paragraph"><div class="image"><img src="Pictures/2018-06-17_12-04-32.png">this is a picture</div> : text</div>
<div class="paragraph"><div class="image"><img src="Pictures/2018-05-16_16-03-00.png">this is another picture</div> : other text</div>
...
脚本是:
$("div.image").mouseover(function(){
var pos = $(this).offset();
console.log('pos_top :', pos.top);
每次滚动时,将鼠标悬停在图片上都会显示不同的数字pos.top
。这怎么可能?
解决方案
推荐阅读
- django - AWS S3 存储桶上的 Django 静态文件
- php - 使用 Twitter API 和 Guzzle 检索图像媒体
- vba - VBA 集合不添加数字项
- windows - Windows 安全对话框和默认凭据提供程序
- python - Python Pandas 比较 2+ 列并选择不同的列
- blockchain - 如何限制谁可以呼叫我在 Sophia 的入口点?
- c# - 为什么与我的 Blazor 应用程序的连接被拒绝?
- javascript - $getJson 总是返回 404
- java - Volley StringRequest 结果为空错误
- python - 通过两个标准在数据框中聚合和排列结果