Skip to content

Commit

Permalink
Fix offset bug with moveElement optimization. Fixes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
zackbloom committed Dec 13, 2013
1 parent b84a0e3 commit bc1fb2f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
3 changes: 3 additions & 0 deletions docs/css/intro.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* {
box-sizing: border-box; }

body {
position: relative; }

.yellow-box {
width: 100px;
height: 100px;
Expand Down
3 changes: 3 additions & 0 deletions docs/sass/intro.sass
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ $exampleHeight: 180px
*
box-sizing: border-box

body
position: relative

.yellow-box
width: 100px
height: 100px
Expand Down
15 changes: 11 additions & 4 deletions tether.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ class Tether
$offsetParent = @$target.offsetParent()
offsetPosition = $offsetParent.offset()

offsetBorder = {}
for side in ['top', 'left', 'bottom', 'right']
offsetBorder[side] = parseFloat $offsetParent.css "border-#{ side }-width"

offsetPosition.left += offsetBorder.left
offsetPosition.top += offsetBorder.top

offsetPosition.right = document.body.scrollWidth - offsetPosition.left - $offsetParent.width()
offsetPosition.bottom = document.body.scrollHeight - offsetPosition.top - $offsetParent.height()

Expand All @@ -288,10 +295,10 @@ class Tether
# It's position relative to the target's offset parent (absolute positioning when
# the element is moved to be a child of the target's offset parent).
next.offset =
top: next.page.top - offsetPosition.top + scrollTop
left: next.page.left - offsetPosition.left + scrollLeft
right: next.page.right - offsetPosition.right - scrollLeft
bottom: next.page.bottom - offsetPosition.bottom - scrollTop
top: next.page.top - offsetPosition.top + scrollTop + offsetBorder.top
left: next.page.left - offsetPosition.left + scrollLeft + offsetBorder.left
right: next.page.right - offsetPosition.right - scrollLeft + offsetBorder.right
bottom: next.page.bottom - offsetPosition.bottom - scrollTop + offsetBorder.bottom

# We could also travel up the DOM and try each containing context, rather than only
# looking at the body, but we're gonna get diminishing returns.
Expand Down
18 changes: 13 additions & 5 deletions tether.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tether.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bc1fb2f

Please sign in to comment.