Skip to content

Commit

Permalink
Fixes #386, Element.position not working correctly when window is scr…
Browse files Browse the repository at this point in the history
…olled

https://mootools.lighthouseapp.com/projects/24057/tickets/386

- Adds test from ticket for hugely offset document
- Reverts change to Element.Position which adds scroll offset again to
  calculated position
  • Loading branch information
fat authored and timwienk committed Sep 26, 2010
1 parent f5e5a1f commit 893809c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
5 changes: 1 addition & 4 deletions Source/Element/Element.Position.js
Expand Up @@ -195,13 +195,10 @@ Element.implement({
pos.top+= winScroll.y;
pos.left+= winScroll.x;
}
var relScroll = rel.getScroll();
if (options.ignoreScroll){
var relScroll = rel.getScroll();
pos.top -= relScroll.y;
pos.left -= relScroll.x;
} else {
pos.top += relScroll.y;
pos.left += relScroll.x;
}

if (options.ignoreMargins){
Expand Down
47 changes: 47 additions & 0 deletions Tests/Element/Element.Position_(scrolled).html
@@ -0,0 +1,47 @@
<style>
div.container {
height: 800px;
}
#element {
width: 100px;
height: 100px;
background: black;
line-height: 30px;
text-align: center;
font-size: 16px;
color: white;
}
.padding {
height: 600px;
}
</style>

<div class="container">

<p>
The black box should always go to center when clicking each of the
three buttons -- important to test this relative to scrollPosition.
Scroll down for the other buttons.
</p>

<div id="element">Companion square</div>

<input type="button" value="Click here to position the element centered (1/3)" />

<div class="padding"></div>

<input type="button" value="Click here to position the element centered (2/3)" />

<div class="padding"></div>

<input type="button" value="Click here to position the element centered (3/3)" />

</div>

<script src="/depender/build?require=More/Element.Position,Core/Element.Event"></script>

<script type="text/javascript">
$$('input').addEvent('click', function(){
document.id('element').position();
});
</script>

0 comments on commit 893809c

Please sign in to comment.