Scrolls to the top of the page or to a page element, only showing the button when you have scrolled down 50px from the top of the screen. Button fades in and out at the bottom right of the screen.
Created
June 23, 2020 00:10
-
-
Save enzienza/40c8637e1ca0650251931ea4b0265482 to your computer and use it in GitHub Desktop.
Smooth Scroll to top button + font awesome
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
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet"> | |
<div class='thetop'></div> | |
<div class='testheight'>Some exciting content... Scroll down for the button to appear.<br><br> | |
<i class="fa fa-4x fa-thumbs-up fa-spin"></i> | |
</div> | |
<div class='scrolltop'> | |
<div class='scroll icon'><i class="fa fa-4x fa-angle-up"></i></div> | |
</div> |
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
$(window).scroll(function() { | |
if ($(this).scrollTop() > 50 ) { | |
$('.scrolltop:hidden').stop(true, true).fadeIn(); | |
} else { | |
$('.scrolltop').stop(true, true).fadeOut(); | |
} | |
}); | |
$(function(){$(".scroll").click(function(){$("html,body").animate({scrollTop:$(".thetop").offset().top},"1000");return false})}) |
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
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
*{ | |
font-family:tahoma; | |
} | |
/* .testheight Not required - unless testing ;) */ | |
.testheight { | |
height:1200px; | |
font-size:20px; | |
text-align:center; | |
padding:100px 20px; | |
} | |
.scrolltop { | |
display:none; | |
width:100%; | |
margin:0 auto; | |
position:fixed; | |
bottom:20px; | |
right:10px; | |
} | |
.scroll { | |
position:absolute; | |
right:20px; | |
bottom:20px; | |
background:#b2b2b2; | |
background:rgba(178,178,178,0.7); | |
padding:20px; | |
text-align: center; | |
margin: 0 0 0 0; | |
cursor:pointer; | |
transition: 0.5s; | |
-moz-transition: 0.5s; | |
-webkit-transition: 0.5s; | |
-o-transition: 0.5s; | |
} | |
.scroll:hover { | |
background:rgba(178,178,178,1.0); | |
transition: 0.5s; | |
-moz-transition: 0.5s; | |
-webkit-transition: 0.5s; | |
-o-transition: 0.5s; | |
} | |
.scroll:hover .fa { | |
padding-top:-10px; | |
} | |
.scroll .fa { | |
font-size:30px; | |
margin-top:-5px; | |
margin-left:1px; | |
transition: 0.5s; | |
-moz-transition: 0.5s; | |
-webkit-transition: 0.5s; | |
-o-transition: 0.5s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment