javascript - Sticky Element catching on down scroll and catching on up scroll -


i have sticky side bar , right using js have catching , staying fixed t point. when scroll need catch , not go further starting point. code far.

$(window).scroll(function(e){    $el = $('.why_social');   if ($(this).scrolltop() > 735 && $el.css('position') != 'fixed'){    $('.why_social').css({'position': 'fixed', 'top': '-62px'});    }  }); 

you should have add opposite check. should started.

$(window).scroll(function(e){      $el = $('.why_social');      if ($(this).scrolltop() > 735 && $el.css('position') !== 'fixed') {          $('.why_social').css({'position': 'fixed', 'top': '-62px'});      }     if ($(this).scrolltop() <= 735 && $el.css('position') === 'fixed') {  {         $('.why_social').css({'position': ''}); // remove `position: fixed;`     } }); 

btw: if you've not got heart set on custom solution, see if bootstrap's affix plugin meets needs. can source code @ https://github.com/twbs/bootstrap/blob/master/js/affix.js , other link take documentation on how use it. should have add .affix { position: fixed; } css.


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -