afonsoalban
12/26/2016 - 6:19 PM

Show a fixed header after scrolling 200 pixels vertically.

Show a fixed header after scrolling 200 pixels vertically.

var ultimoScroll = 0, scrolled = false;
window.addEventListener('scroll', function(e) {
  ultimoScroll = window.scrollY;
  
  if (!scrolled) {
    window.requestAnimationFrame(function() {
        headerFixo(ultimoScroll);
        scrolled = false;
    });
  }
  scrolled = true;
});

function headerFixo(scroll_pos) {
    if( scroll_pos > 200 ){
        jQuery('.header_fixo').fadeIn();
    } else {
        jQuery('.header_fixo').fadeOut();
    }
}