jquery - How to create a Facebook-like sticky bar -


here check video see mean (video)

now notice left bar when scroll. when scroll bottom of bar, bar becomes sticky, , no matter how far scrolled, scroll bar scrolls until reaches top of bar again.

so far, did come sticky bar, want if scroll bar scrolls until reaches top facebook style.

this code far

function stickdown($el, margin, position){      var elpos = $el.offset().top + $el.height() + margin;      $(window).scroll(function(){         var wins = $(window).scrolltop();         var winh = $(window).height();          if(wins + winh > elpos)             $el.attr('style', 'position:fixed;bottom:'+margin+'px;top:auto;');         else             $el.attr('style', 'position:'+position+';');             })  }  $(document).ready(function(){     stickdown($('div#bar'), 10, 'relative'); }) 

i have figured out. here new code

var winscrtop = 0, oldscrtop = 0; $(window).scroll(function(){     winscrtop = $(this).scrolltop();     winh = $(this).height();     $bar = $('div#bar');     bartop = $bar.offset().top;     barh = $bar.height();     margin = 10;     scrh = winscrtop + winh;     topmar = bartop - winscrtop;     allbar = bartop + barh + margin;     if(winscrtop > oldscrtop){         if(scrh > allbar && topmar < 100){             $bar.css({                 position:'fixed',                 top: topmar+'px'             })         } else {             $bar.css({                 position:'absolute',                 top: bartop+'px'             })         }     } else {         if(scrh > allbar){             nin = winscrtop - bartop;             $bar.css({                 position:'absolute',                 top: nin+'px'             })         }         if(topmar > 99){             $bar.css({                 position:'fixed',                 top: '100px'             })         }     }     oldscrtop = winscrtop; }) 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -