Created
August 29, 2017 22:30
-
-
Save enlacee/30f5189d1d15602cb9914b300ea1d670 to your computer and use it in GitHub Desktop.
hacer scroll con el tamaño de cabecera
This file contains hidden or 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
function getHeightHeader() { | |
var height = 0; | |
if ($('.header-page').length === 1) { | |
$headerPage = $('.header-page'); | |
if ($headerPage.css('position') === 'fixed') { | |
height = $headerPage.height(); | |
} | |
} | |
return height; | |
} | |
var sizeHeaderDesktop = getHeightHeader(); | |
function setScrollContent(domJquerySelected){ | |
$sectionJqueryDom = domJquerySelected; | |
$("html, body").animate( | |
{ | |
scrollTop: $sectionJqueryDom.offset().top - sizeHeaderDesktop | |
}, | |
{ | |
duration: 1000, | |
complete: function() { | |
if (sizeHeaderDesktop !== getHeightHeader()) { | |
sizeHeaderDesktop = getHeightHeader(); | |
$("html, body").animate({scrollTop: $sectionJqueryDom.offset().top - sizeHeaderDesktop}); | |
} | |
} | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment