Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: include.postload.js

Issue 6527157522137088: Issue 1082 - Use Element.getBoundingClientRect() to position overlays (Closed)
Patch Set: Created Jan. 26, 2015, 11:12 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include.postload.js
===================================================================
--- a/include.postload.js
+++ b/include.postload.js
@@ -235,21 +235,6 @@
return false;
}
-// Gets the absolute position of an element by walking up the DOM tree,
-// adding up offsets.
-// I hope there's a better way because it just seems absolutely stupid
-// that the DOM wouldn't have a direct way to get this, given that it
-// has hundreds and hundreds of other methods that do random junk.
-function getAbsolutePosition(elt) {
- var l = 0;
- var t = 0;
- for(; elt; elt = elt.offsetParent) {
- l += elt.offsetLeft;
- t += elt.offsetTop;
- }
- return [l, t];
-}
-
// Adds an overlay to an element, which is probably a Flash object
function addElementOverlay(elt) {
var zIndex = "auto";
@@ -286,11 +271,11 @@
overlay.prisoner = elt;
overlay.className = "__adblockplus__overlay";
overlay.setAttribute('style', 'opacity:0.4; display:inline-box; overflow:hidden; box-sizing:border-box;');
- var pos = getAbsolutePosition(elt);
- overlay.style.width = elt.offsetWidth + "px";
- overlay.style.height = elt.offsetHeight + "px";
- overlay.style.left = pos[0] + "px";
- overlay.style.top = pos[1] + "px";
+ var rect = elt.getBoundingClientRect();
+ overlay.style.width = rect.width + "px";
+ overlay.style.height = rect.height + "px";
+ overlay.style.left = (rect.left + window.scrollX) + "px";
+ overlay.style.top = (rect.top + window.scrollY) + "px";
overlay.style.position = position;
overlay.style.zIndex = zIndex;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld