javascript - Element move by Jquery scroll -
i have problem element position moving scroll event. problem: i'm scrolling page , append 1px css top value (every scroll). after i'm scrolling page down, , remove 1px css top value. think it's return original position, not. here code:
var lastscroll = $(window).scrolltop(); $(window).scroll(function(env) { var scroll = $(this).scrolltop(); if (scroll > lastscroll){ console.log('scroll down'); $('#home>article').css({ top: "+="+1+"px" }); } else { console.log('scroll up'); $('#home>article').css({ top: "-="+1+"px" }); lastscroll = scroll; });
thanks idea!
hope might help, used while ago. have been using:
<script type="text/javascript">// <![cdata[ $(window).scroll(function () { var ttop = $('.container').position().top; var hcltb = $('.container').height(); var mtop = $(window).scrolltop(); if (mtop > ttop) { if (mtop < (ttop + hcltb - 400)) { $('.internal_prev').css('top', (mtop - ttop + 300)); $('.internal_next').css('top', (mtop - ttop + 300)); $('.internal_commands').css('top', (mtop - ttop + 300)); } } }); // ]]></script>
this cause div class="container" act main container. cause internal_* classes scroll , down inside div set internal padding of 400.
it not perfect here go.
Comments
Post a Comment