jquery - HTML Top Bar fixed and rescalling when scrolling -
i want make topbar not fixed when scrolling, decreasing size in height. when scroll down, know how make fixed, wanna know how improve site's visibility rescaling height.
example: http://www.kriesi.at/themedemo/?theme=enfold-overview
i tried search solution fixed topbar, not size.
you listen scroll event
- not best solution regarding performance, quick , easy use solution now.
$(window).scroll(function() { if ($(window).scrolltop() > ($(window).height()-80)) { $('.navigation').addclass('nav--closed')// > 100px top - show div } else { $('.navigation').removeclass('nav--closed')// > 100px top - show div // <= 100px top - hide div } });
and css be:
.navigation { position: fixed; top: 0; left: 0; height: 8em; width: 100%; z-index: 5; background-color: black; transform: translate3d(0,0,0); transition:height 0.4s ease-in-out; color: white; } .navigation.nav--closed{ background-color: $colorwhite; height: 2em; }
take @ fiddle should self explaining.
besides scroll
might try requestanimationframe faster , more performant! raf
Comments
Post a Comment