Skip to content

Instantly share code, notes, and snippets.

@webdelin
Created January 22, 2018 20:26
Show Gist options
  • Select an option

  • Save webdelin/c881051851ae52e3f865d5cf9ff49025 to your computer and use it in GitHub Desktop.

Select an option

Save webdelin/c881051851ae52e3f865d5cf9ff49025 to your computer and use it in GitHub Desktop.
ScrollToTop-JS
var back_to_top_button = ['<a title="zum Menu" href="#top" class="scrollToTop bg-primary">TOP</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