Javascript 当我聚焦dom而不是IE中的视图时,body scrollTop发生了更改
当我像这样聚焦DOM时,如何防止IE中的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();
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吗?