Created
January 22, 2018 20:26
-
-
Save webdelin/c881051851ae52e3f865d5cf9ff49025 to your computer and use it in GitHub Desktop.
ScrollToTop-JS
This file contains hidden or 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="#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