Created
January 22, 2018 20:27
-
-
Save webdelin/8cfe0c6d434d3b3deb3fe7310d42d8fb to your computer and use it in GitHub Desktop.
ScrolToTop-JS
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
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