Firefox 滚动顶部在 zIndex 更改时重置

发布于 2024-10-16 00:04:40 字数 1729 浏览 3 评论 0原文

每当我更改给定 div 的 zIndex(甚至更改为相同的值)时,其 scrollTop 属性都会重置,并且会滚动回开始位置。这会给我的网站带来非常难看的效果(重新绘制时整个 div 会变慢并出现黑色矩形)。重置scrollTop后,我可以将其设置回来,但这会导致另一次丑陋的重画。

这个FF bug快把我逼疯了!我在 mozilla https://bugzilla.mozilla.org/show_bug.cgi?id 提交了一个错误=623937,但他们不愿意为此工作!拜托,如果有人知道如何用一些 javascript 魔法来解决这个问题?也许可以使用 HTMLElement 原型来以某种方式覆盖scrollTop?

这是一个小测试用例”

<html>
<head>
<style type="text/css">
div#parentDiv
{
position: absolute;
top: 10px;
left: 10px;
width: 300px;
height: 200px;
background-color: green;
}
div#elementToScroll
{
position: absolute;
top: 40px;
left: 40px;
width: 200px;
height: 100px;
overflow-y: hidden;
background-color: blue;
color: white;
}
</style>
</head>

<body>

<div id="parentDiv">
This is the parent DIV
<div id="elementToScroll">This is the child div with overflow-y: hidden and content a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of ; </div>
</div>

<script>
var parentDIV = document.getElementById("parentDiv");
var elementToScroll = document.getElementById("elementToScroll");
alert ("elementToScroll.scrollTop initial: " + elementToScroll.scrollTop);
elementToScroll.scrollTop = 20;
alert ("We set elementToScroll.scrollTop = 20: current value is: " + elementToScroll.scrollTop);
parentDIV.style.zIndex = 0;
alert ("We set parentDIV.style.zIndex and now elementToScroll.scrollTop is: " + elementToScroll.scrollTop);
</script>

</body>
</html>

Whenever I change zIndex of given div (even to the same value) its scrollTop property resets and it scrolls back to start. This causes a very ugly effect to my site (slowdown and black rectangle over the entire div while it repaints). After scrollTop reset I can set it back, but this causes yet another ugly repaint.

This FF bug is driving me mad! I submitted a bug in mozilla https://bugzilla.mozilla.org/show_bug.cgi?id=623937 but they don't care to work on it! Please, if somebody knows how to workaround this issue with some javascript magic? Maybe play with the HTMLElement prototype to somehow override scrollTop?

Here goes a little test case"

<html>
<head>
<style type="text/css">
div#parentDiv
{
position: absolute;
top: 10px;
left: 10px;
width: 300px;
height: 200px;
background-color: green;
}
div#elementToScroll
{
position: absolute;
top: 40px;
left: 40px;
width: 200px;
height: 100px;
overflow-y: hidden;
background-color: blue;
color: white;
}
</style>
</head>

<body>

<div id="parentDiv">
This is the parent DIV
<div id="elementToScroll">This is the child div with overflow-y: hidden and content a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of a lot of ; </div>
</div>

<script>
var parentDIV = document.getElementById("parentDiv");
var elementToScroll = document.getElementById("elementToScroll");
alert ("elementToScroll.scrollTop initial: " + elementToScroll.scrollTop);
elementToScroll.scrollTop = 20;
alert ("We set elementToScroll.scrollTop = 20: current value is: " + elementToScroll.scrollTop);
parentDIV.style.zIndex = 0;
alert ("We set parentDIV.style.zIndex and now elementToScroll.scrollTop is: " + elementToScroll.scrollTop);
</script>

</body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光的暖冬 2024-10-23 00:04:40

我测试过,Firefox 4 没有任何问题:

在此处输入图像描述

I tested and nothing is wrong with Firefox 4:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文