如:.testCSS{position: absolute;left:0%;top:%10; width:20%; height:20%;}
<img id='idImg' alt='1.jpg' class=testCSS/>js中怎么获取left,top,width,height的真是位置,而非百分数 var image = document.getElementById('imgId');
window.getComputedStyle(image).left; //这个获取的是百分比
<img id='idImg' alt='1.jpg' class=testCSS/>js中怎么获取left,top,width,height的真是位置,而非百分数 var image = document.getElementById('imgId');
window.getComputedStyle(image).left; //这个获取的是百分比
解决方案 »
- 数组重组
- |zyciis| 发现一款非常好的alert组件,ymPrompt 但里面的调用iframe,那在iframe里面怎么来关闭这个DIV呢,谢谢
- 一个关于window.open打开窗口的问题(十分奇怪)
- JS的RAIDO取值函数问题
- 在哪可以找到MSN API的说明书呀,急!急!呀
- js引用和iframe引用,哪个更占用页面打开速度?
- 求救checkbox全选 老板催的急 在线等 谢谢
- [求助]关于图片自动缩小的问题
- 数组基础问题(续)
- 如何在代码上解决网页加载慢,偶尔时间长了会显示糟糕网页无法显示的问题
- 点击button怎么能才能改变value的值
- 小白求助~No 'Access-Control-Allow-Origin' header is present on the requested resourc
image.offsetLeft 数字
https://blog.csdn.net/gao_xu_520/article/details/80365799注意这个是获取元素到窗口可视范围的距离。如果获取元素到页面的距离需要加上页面滚动条的位置
rectObject.left + (document.body.scrollLeft || document.documentElement.scrollLeft)
rectObject.top + (document.body.scrollTop || document.documentElement.scrollTop)
可能是因为你设置的百分比并没有生效。元素要设置百分比生效,需要先设置 html, body {height: 100%;}