javascript - How to apply var height = $(window).height() - 20; to .followTo() function -


i have script. pretty simple. js skills shaky @ best. makes navigation (which positioned bottom of window) scroll content until reaches top of page remains fixed. or "sticky"

the issue im having since banner 100% in height. .followto(830); works on screen resolution. how make followto() find windows current height , follow height , subtract 20px followto value? ideal. can accomplished simply?

    var windw = this;     $.fn.followto = function ( pos ) {         var $this = this,             $window = $(windw);         $window.scroll(function(e){             if ($window.scrolltop() > pos) {                 $this.css({                     position: 'fixed',                     top: "20px"                 });             } else {                 $this.css({                     position: 'absolute',                     bottom: '0',                  });             }         });     };     $('#mainnav').followto(830); 

someone said need use var height = $(window).height() - 20; not sure how apply , refused elaborate instead downvoting posts , refering me entire jquery api.. isnt learning style.

ive attempted use if ($(document).height() - $window.height() - $('#mainnav').scrolltop() < pos) think im messing syntax?

just use var height = $(window).height() - 20; in place of 830 this:

var height = $(window).height() - 20; $('#mainnav').followto(height); 

just keep in mind window size can change (for example browser window gets resized or device's orientation changes)


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -