/ Published in: JavaScript
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
// javascript
$(function() {
$window = $(window);
$link = $("#scrollToTop"); // your link to show when user scrolls down
$link.click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow"); // this is the gist of the script, scroll to top (scrollTop: 0)
});
$window.scroll(function() {
if ($window.scrollTop() <= 0) {
$link.fadeOut("fast");
} else {
$link.fadeIn("fast");
}
})
// css
#scrollToTop:link,
#scrollToTop:visited {
display: none;
position: fixed;
top: 15px;
right: 15px;
padding: 10px 20px;
font-size: 16px;
font-weight: bold;
text-decoration: none;
background: #ccc;
color: #333;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                