Created
June 19, 2018 15:46
-
-
Save Martydesign/511e8d4b34be46041ce9e7354ba2dea0 to your computer and use it in GitHub Desktop.
Back to top scrolling function - arrow using jQuery.
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
// make the link to scroll to top of the page | |
var backToTop = $('<a>', { | |
href: '#home', | |
class: 'back-to-top', | |
html: '<i class="fa fa-caret-up fa-5x"></i>' | |
}); | |
// add link to the page and establish a scrolling function | |
backToTop | |
.hide() | |
.appendTo('body') | |
.on('click', function() { | |
$('html,body').animate({ scrollTop: 0 }); | |
}); | |
// show only if we are enough deep (this sounds little bit pervers) in the page | |
var win = $(window); | |
win.scroll(function() { | |
if ( win.scrollTop() >= 300 ) backToTop.fadeIn(); | |
else backToTop.hide(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment