From daefc058b6ae85d0db0b91af5ab0de988e6d5173 Mon Sep 17 00:00:00 2001 From: Jason Johnston Date: Wed, 2 Jun 2010 18:55:01 -0600 Subject: [PATCH] Change the way we detect whether an element has changed position/size to use getBoundingClientRect rather than offsetLeft/Top/etc. -- this prevents situations where the element's position relative to its positioning container actually changes but its offsetLeft/Top stay the same. Closes #15. --- sources/event_handlers.js | 10 +++---- tests/margin-auto-tests.html | 57 ++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 tests/margin-auto-tests.html diff --git a/sources/event_handlers.js b/sources/event_handlers.js index 6a5163f..eadf1e6 100644 --- a/sources/event_handlers.js +++ b/sources/event_handlers.js @@ -10,11 +10,11 @@ var lastW, lastH, lastX, lastY, */ function update() { init(); - var el = element, - x = el.offsetLeft, - y = el.offsetTop, - w = el.offsetWidth, - h = el.offsetHeight, + var rect = element.getBoundingClientRect(), + x = rect.left, + y = rect.top, + w = rect.right - x, + h = rect.bottom - y, i, len; if( x !== lastX || y !== lastY ) { diff --git a/tests/margin-auto-tests.html b/tests/margin-auto-tests.html new file mode 100644 index 0000000..a3eea82 --- /dev/null +++ b/tests/margin-auto-tests.html @@ -0,0 +1,57 @@ + + + + + + PIE Position After Window Resize + + + + + + +

PIE Position After Window Resize

+ +

Resize Window.

+ +

Expected Behavior

+ +

Borders should update position with box.

+ +
+
+ PIE. +
+ +
+ No PIE. +
+
+ + \ No newline at end of file