Created
February 6, 2017 21:19
-
-
Save Waidoss/154797cbdfe7cff459e799b8dbedf7ec to your computer and use it in GitHub Desktop.
scroll_to_top
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
$(function() { | |
// Поскольку кнопка за аппендена то делаем через ON | |
$("body").on("click", ".top", function() { | |
$("html, body").animate({scrollTop: 0}, "slow"); | |
}); | |
$("body").append('<div class="top">^'); | |
// Функция скроллинга странички, добавляем класс active к заапенденной .top кнопке, если высота окна | |
//больше его первоначальнойвысоты... | |
$(window).scroll(function() { | |
if($(this).scrollTop() > $(this).height()) { | |
$(".top").addClass("active"); | |
} | |
else{ | |
$(".top").removeClass("active"); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment