如何滚动到页面中间(50%)
如果不使用流行的scrollTo插件,我如何滚动到页面/div的垂直中间(50%)?
Without using the popular scrollTo plugin, how can I scroll to the vertical middle (50%) of the page/div?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这会将 div 的内部滚动滚动到其垂直中间
This scrolls the internal scroll of a div to it's vertical middle
JQuery - 跳转到滚动 div 垂直/水平中间的
垂直
/水平
将“#scroll-div”替换为您的 div。 “身体”对我不起作用。
jsfiddle
这是唯一适合我的解决方案。实际上,它是一个 2 小时尝试和错误的解决方案,可以很好地完成其工作。也许有人可以解释为什么scrollTop永远不会达到prop(“scrollheight”)的值并且diff和middle的书面计算是必要的。
JQuery - jump to vert/hori middle of scroll-div
vertical
horizontal
Replace "#scroll-div" with your div. "body" isn't working for me.
jsfiddle
Thats the only solution that works properly for me. Actually its an 2h-try'n'error solution thats do its job pretty well. Maybe someone could explain why scrollTop is never reaching the value of prop("scrollheight") and the written calculation of diff and middle is necessary.