jquery - 如何从 windowheight 获取滚动 div 的底部偏移量
问题描述
我只想偏移红色框的底部空间,当我滚动正文滚动时,红色框将某些部分隐藏到正文滚动中,我将单击一个按钮以获取红色框的底部偏移量参见图片以获取参考
//want offset bottom of box after some scroll of body scroll
.divHasScroll {
height: 200px;
width: 350px;
background: red;
overflow: auto
}
<div class="divHasScroll">
<p> text in box</p>
<p> text in box</p>
<p> text in box</p>
<p> text in box</p>
<p> text in box</p>
<p> text in box</p>
<p> text in box</p>
<p> text in box</p>
<p> text in box</p>
<p> text in box</p>
<p> text in box</p>
</div>
<p> text in window scrolling section</p>
<p> text in window scrolling section</p>
<p> text in window scrolling section</p>
<p> text in window scrolling section</p>
<p> text in window scrolling section</p>
<p> text in window scrolling section</p>
<p> text in window scrolling section</p>
<p> text in window scrolling section</p>
<p> text in window scrolling section</p>
<p> text in window scrolling section</p>
<p> text in window scrolling section</p>
<p> text in window scrolling section</p>
<p> text in window scrolling section</p>
<p> text in window scrolling section</p>
解决方案
如果您的容器是主体,您可以通过此计算获得偏移量
alert($('body').height() - $('.divHasScroll').height());
您需要容器的高度 - 可滚动 div 的高度。
偏移属性仅适用于顶部或左侧,在这种情况下它不会为您服务。
希望这可以帮助。
推荐阅读
- knapsack-problem - 查找总价值大于或等于目标值的最便宜的项目组合
- java - 在控制器 Java 中成功操作后,如何在屏幕上显示成功消息?
- kotlin - 如何在 Kotlin Native 中设置协程调度程序的线程优先级
- flutter - 如何使用 Flutter Gallery 启动应用程序启动 Flutter 项目?
- php - 无法从 Drupal Commerce 2 中的当前会话购物车获取 order_id
- python - 为什么从带有 for 循环的 pandas 数据框创建数组时,我的数组的每个元素都包含在 array([]) 中?
- docker - 未找到 RabbitMQ 指标
- python - 在 Python Flask 中获取用户的位置
- .net - My.Computer.FileSystem.WriteAllText 在文件打开时不会出现任何异常
- javascript - 检查对象数组是否包含来自另一个对象数组的多个值并删除重复项