Skip to content

Instantly share code, notes, and snippets.

@webdelin
Created January 22, 2018 20:27
Show Gist options
  • Save webdelin/8cfe0c6d434d3b3deb3fe7310d42d8fb to your computer and use it in GitHub Desktop.
Save webdelin/8cfe0c6d434d3b3deb3fe7310d42d8fb to your computer and use it in GitHub Desktop.
ScrolToTop-JS
var back_to_top_button = ['<a title="zum Menu" href="#" class="scrollToTop"><i class="ion-chevron-up" aria-hidden="true"></i></a>'].join("");
$("body").append(back_to_top_button)
// Der Button wird ausgeblendet
$(".scrollToTop").hide();
// Funktion für das Scroll-Verhalten
$(function () {
$(window).scroll(function () {
if ($(this).scrollTop() > 300) { // Wenn 100 Pixel gescrolled wurde
$('.scrollToTop').fadeIn();
} else {
$('.scrollToTop').fadeOut();
}
});
$('.scrollToTop').click(function () { // Klick auf den Button
$('body,html').animate({
scrollTop: 0
}, 800);
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment