Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当我聚焦dom而不是IE中的视图时,body scrollTop发生了更改_Javascript_Css_Internet Explorer_Dom_Cross Browser - Fatal编程技术网

Javascript 当我聚焦dom而不是IE中的视图时,body scrollTop发生了更改

Javascript 当我聚焦dom而不是IE中的视图时,body scrollTop发生了更改,javascript,css,internet-explorer,dom,cross-browser,Javascript,Css,Internet Explorer,Dom,Cross Browser,当我像这样聚焦DOM时,如何防止IE中的scrollTop更改 <html> <head> <title>demo</title> <script type="text/javascript"> function test() { document.getElementById('div1').focus();

当我像这样聚焦DOM时,如何防止IE中的
scrollTop
更改

<html>
    <head>
        <title>demo</title>
        <script type="text/javascript">
            function test() {
                document.getElementById('div1').focus();
                //document.body.scrollLeft = 0;
                //document.body.scrollTop = 0;
            }
        </script>
    </head>
    <body onload="test()" scroll='no' style='overflow:hidden'>

        <div id="div0" style="width:1400px;height:700px;background:#333333;position:absolute;"> </div>

        <div id="div1" style="top:1500px;width:1500px;height:300px;background:#DDDDDD;position:absolute; "> </div>

    </body>
</html>

演示
功能测试(){
document.getElementById('div1').focus();
//document.body.scrollLeft=0;
//document.body.scrollTop=0;
}

我不想重置scrollTop=0,因为它会使身体抖动。

这就是你想要的效果吗

<!DOCTYPE html>
<html>
<head>
    <title>demo</title>
    <style>
        body {
            margin: 0;
            padding: 0;
        }

        #div0, #div1 {
            position: absolute;
            height: 100px;
            width: 100%;
        }

        #div0 {
            background: #333;
        }

        #div1 {
            background: #ddd;
        }
    </style>
</head>
<body>
    <div id="div0" style="height:700px;"> </div>

    <div id="div1" style="top:1500px;height:300px;"> </div>

    <script type="text/javascript">
        (function() {
            document.getElementById('div1').focus();
        })();
    </script>
</body>
</html>

演示
身体{
保证金:0;
填充:0;
}
#第0部分,第1部分{
位置:绝对位置;
高度:100px;
宽度:100%;
}
#第0课{
背景:#333;
}
#第一组{
背景:ddd;
}
(功能(){
document.getElementById('div1').focus();
})();

您有JSFIDLE吗?