我有一些 javascript 可以处理在我的网站上打开模式弹出窗口,它还设置了 overflow-y
<html>
上的属性(property)元素到 hidden
.在 Chrome 和 IE 中,这按预期工作 - 滚动条隐藏,模式弹出窗口后面的页面保持在相同的滚动位置。当弹出窗口关闭时,overflow-y
设置为 scroll
并且页面处于与之前相同的状态和位置。
但是在 Firefox 中,只要 overflow-y
更改为 hidden
页面滚动位置跳到最顶部,因此当弹出窗口关闭时, View 对用户来说已经改变 - 不理想。
问题可见on this jsfiddle
是否有针对此行为的解决方案?
最佳答案
不要在 html
上使用 overflow: hidden
,只能在 body
上使用。
我遇到了同样的问题,但通过删除 html
修复了它。
相反:
$('body, html').css('overflow', 'hidden');
做:
$('body').css('overflow', 'hidden');
关于javascript - 设置溢出-y : hidden; causes the page to jump to the top in Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15019510/