Skip to content

Instantly share code, notes, and snippets.

@reinaldomendes
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reinaldomendes/200f03d20bc5d9f19bbc to your computer and use it in GitHub Desktop.
Save reinaldomendes/200f03d20bc5d9f19bbc to your computer and use it in GitHub Desktop.
barra fixa quando a rolagem escondê-la
body.fixed-header .header-container{
position: fixed;
/*... Outros Css para barra fixa aqui*/
}
jQuery(function($){
var targetSelector = '.header-container';//use your class or selector heare
var fixedClassName = 'fixed-header';//nome da classe que será adicionada no body, ver css abaixo
var $header = $(targetSelector);
var wrapperClass = $header.attr('class').replace(/\s/,'_') + '-wrapper';
var $wraper = $('<div/>').addClass(wrapperClass);
$header.wrap($wraper);
var barSize = $header.height();
$wraper = $('.' + wrapperClass);
var $window = $(window);
$window.scroll(function(evt){
var breakpoint = $window.scrollTop() - (barSize + 100);
if (breakpoint > 0){
if(! $(document.body).hasClass(fixedClassName)){
$wraper.css('height',barSize);
$(document.body).addClass(fixedClassName);
}
} else {
if( $(document.body).hasClass(fixedClassName)){
$wraper.css('height','auto')
$(document.body).removeClass(fixedClassName);
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment