获取元素到body的距离: <script> function offsetDis(obj) { var l = 0, t = 0; while(obj) { l = l + obj.offsetLeft + obj.clientLeft; t = t + obj.offsetTop + obj.clientTop; obj = obj.offsetParent; } return {left: l, top: t}; } </script>…
一.getComputedStyle getComputedStyle 是一个可以获取当前元素所有最终使用的CSS属性值.返回的是一个CSS样式声明对象([object CSSStyleDeclaration]),只读. 语法如下: var style = window.getComputedStyle("元素", "伪类"); //例 var dom = document.getElementById("test"); var style =…
JavaScript通过ID获取元素坐标 function getElementPos(elementId) { var ua = navigator.userAgent.toLowerCase(); var isOpera = (ua.indexOf('opera') != -1); var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof var el = document.get…