1

每当我更改给定 div 的 zIndex (甚至更改为相同的值)时,它的 scrollTop 属性都会重置并滚动回开始。这会对我的网站造成非常难看的效果(在重新绘制时整个 div 上的减速和黑色矩形)。在 scrollTop 重置后,我可以将其重新设置,但这会导致又一次丑陋的重绘。

这个 FF 虫子快把我逼疯了!我在 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>
4

1 回答 1

1

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

在此处输入图像描述

于 2011-02-06T20:17:16.577 回答