Last active
November 14, 2016 04:29
-
-
Save Scretch-1/b8073a0566a14dfb8d712561ef7b77cb to your computer and use it in GitHub Desktop.
JS Присвоение класса элементу при скролле
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
// при скролле начиная от верха страницы элемента с любым позиционированием | |
$(window).scroll(function() { | |
if ($(this).scrollTop() > 50) { | |
$('.header-home').addClass("fixo"); | |
} else { | |
$('.header-home').removeClass("fixo"); | |
} | |
}); | |
// при скролле от верха страницы элемента с позиционированием "fixed" | |
$(window).scroll(function() { | |
if ($(".header-home").offset().top>50) { | |
$(".header-home").addClass("fixo"); | |
} | |
else { | |
$(".header-home").removeClass("fixo"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment