jquery - How to get the height of an element and use it in a function? -


i'm trying use jquery determine height of element , determine if user has scrolled distance. application have header followed navbar. user scrolls down page header disappear , navbar stay fixed top of screen. have working using following code:

    <script type="text/javascript"> jquery(window).scroll(function () {  if (jquery(this).scrolltop() > 100 ) {     jquery("#top-header").hide(300); } else {     jquery("#top-header").show(300); } 

});

but want use media queries change height of #top-header based on screen size instead of leaving same. i'd determine height of #top-header (or element within it) , use value in function hide it. know can use form of $('#top-header).height i'm not sure how incorporate function.

thanks, cj

instead of predefined height, use jquery height() element function.

var header = $("#top-header");  $(window).scroll(function() {   if ($(this).scrolltop() > header.height()) {     header.hide(300);   } else {     header.show(300);   } }); 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -