标签:over ott 相对 获取 api set cal -o develop
关键API:
mdn:https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
用法:
var rect = element.getBoundingClientRect(); console.log(rect.top, rect.right, rect.bottom, rect.left);
获取相对位置:
var bodyRect = document.body.getBoundingClientRect(), elemRect = element.getBoundingClientRect(), offset = elemRect.top - bodyRect.top; alert(‘Element is ‘ + offset + ‘ vertical pixels from <body>‘);
参考网址:http://stackoverflow.com/questions/442404/retrieve-the-position-x-y-of-an-html-element
我只是个搬运工,一起学习了~
标签:over ott 相对 获取 api set cal -o develop
原文地址:http://www.cnblogs.com/DarkMaster/p/6767662.html