Skip to content

Instantly share code, notes, and snippets.

@Waidoss
Created February 6, 2017 21:19
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 Waidoss/154797cbdfe7cff459e799b8dbedf7ec to your computer and use it in GitHub Desktop.
Save Waidoss/154797cbdfe7cff459e799b8dbedf7ec to your computer and use it in GitHub Desktop.
scroll_to_top
$(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