简体   繁体   English

如何在firefox上使用javascript获取屏幕的左上角坐标

[英]how to get the top left coordinates of the screen with javascript on firefox

I have a <div> element with position: absolute and z-index something big. 我有一个<div>元素, position: absolute和z-index大。 I would like to cover the entire screen with this div with javascript. 我想用javascript将此div覆盖整个屏幕。 This is what I do and it works: 这是我做的,并且有效:

document.getElementById('mydiv').style.top = 0;
document.getElementById('mydiv').style.left = 0;
document.getElementById('mydiv').style.width = '100%';
document.getElementById('mydiv').style.height = '100%';

However, when I scroll down with long webpages, this code displays my div at the top of the page, so the div renders above the region I currently view. 但是,当我向下滚动较长的网页时,此代码将div显示在页面顶部,因此div呈现在我当前查看的区域上方。 How can I change the top and left values so that my div always covers the active field I am viewing? 如何更改顶部和左侧的值,以便我的div始终覆盖我正在查看的活动字段?

I work on firefox 3.6.*. 我正在使用Firefox 3.6。*。

Thank you 谢谢

Change it to position: fixed . 将其更改为position: fixed

Note that this won't work in IE6. 请注意,这在IE6中不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM