xxxxxxxxxx
<!-- the html code -->
<button id="topBtn" title="Go to top">Top</button>
<style>
body{
height:3000px;
}
button{
position:fixed;
bottom:30px;
right:30px;
}
</style>
<script>
$(document).ready(function(){
// When the user scrolls down 20px from the top of the document, show the button
$(window).scroll(function(){
scrollFunction();
});
function scrollFunction() {
if ($(this).scrollTop() > 20) {
$('#topBtn').fadeIn();
} else {
$('#topBtn').fadeOut();
}
}
// When the user clicks on the button, scroll to the top of the document
$('#topBtn').click(function(){
$('html, body').animate({scrollTop: 0}, 800);
return false;
});
});
</script>