Last active
August 29, 2015 14:05
-
-
Save reinaldomendes/200f03d20bc5d9f19bbc to your computer and use it in GitHub Desktop.
barra fixa quando a rolagem escondê-la
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body.fixed-header .header-container{ | |
position: fixed; | |
/*... Outros Css para barra fixa aqui*/ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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