Skip to content

Commit bc1fb2f

Browse files
committed
Fix offset bug with moveElement optimization. Fixes #4
1 parent b84a0e3 commit bc1fb2f

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

docs/css/intro.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
* {
33
box-sizing: border-box; }
44

5+
body {
6+
position: relative; }
7+
58
.yellow-box {
69
width: 100px;
710
height: 100px;

docs/sass/intro.sass

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ $exampleHeight: 180px
55
*
66
box-sizing: border-box
77

8+
body
9+
position: relative
10+
811
.yellow-box
912
width: 100px
1013
height: 100px

tether.coffee

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ class Tether
275275
$offsetParent = @$target.offsetParent()
276276
offsetPosition = $offsetParent.offset()
277277

278+
offsetBorder = {}
279+
for side in ['top', 'left', 'bottom', 'right']
280+
offsetBorder[side] = parseFloat $offsetParent.css "border-#{ side }-width"
281+
282+
offsetPosition.left += offsetBorder.left
283+
offsetPosition.top += offsetBorder.top
284+
278285
offsetPosition.right = document.body.scrollWidth - offsetPosition.left - $offsetParent.width()
279286
offsetPosition.bottom = document.body.scrollHeight - offsetPosition.top - $offsetParent.height()
280287

@@ -288,10 +295,10 @@ class Tether
288295
# It's position relative to the target's offset parent (absolute positioning when
289296
# the element is moved to be a child of the target's offset parent).
290297
next.offset =
291-
top: next.page.top - offsetPosition.top + scrollTop
292-
left: next.page.left - offsetPosition.left + scrollLeft
293-
right: next.page.right - offsetPosition.right - scrollLeft
294-
bottom: next.page.bottom - offsetPosition.bottom - scrollTop
298+
top: next.page.top - offsetPosition.top + scrollTop + offsetBorder.top
299+
left: next.page.left - offsetPosition.left + scrollLeft + offsetBorder.left
300+
right: next.page.right - offsetPosition.right - scrollLeft + offsetBorder.right
301+
bottom: next.page.bottom - offsetPosition.bottom - scrollTop + offsetBorder.bottom
295302

296303
# We could also travel up the DOM and try each containing context, rather than only
297304
# looking at the body, but we're gonna get diminishing returns.

tether.js

Lines changed: 13 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tether.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)