Created
November 26, 2021 07:44
-
-
Save Ginnw2/b24caf8e872ffdb49a78081c75e95b1c to your computer and use it in GitHub Desktop.
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
#html | |
<a class="toTop hidden" href="#top"><i class="fas fa-chevron-up"></i></a> | |
#style | |
.toTop{ | |
position: fixed; | |
right: 50px; | |
bottom: 20px; | |
} | |
.toTop.hidden{ | |
display: none; | |
} | |
#script | |
$(document).scroll(function(){ | |
var y = $(this).scrollTop(); | |
if (y > 800) { | |
$('.toTop').removeClass('hidden'); | |
} else { | |
$('.toTop').addClass('hidden'); | |
} | |
}); | |
$("a[href='#top']").click(function() { | |
$("html, body").animate({ scrollTop: 0 }, "slow"); | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment