Reputation: 540
I am trying to add a position fixed to a div after 100px are scrolled down from the top of the page, and position relative if less than 100px have been scrolled.
<script type='text/javascript'>
window.addEvent('scroll',function(e) {
if ($(this).scroll > 100) {
$$('.my_element').setStyles({
position: "fixed"
});
} else {
$$('.my_element').setStyles({
position: "relative"
});
}
});
</script>
I can use only Mootools or pure JS, no jQuery.
Upvotes: 1
Views: 1469
Reputation: 26165
you can, of course, use David Walsh's ScrollSpy - http://davidwalsh.name/mootools-scrollspy
else, use window.getScroll().y
to get the current scrollTop etc.
Upvotes: 2