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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -