Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhileshdarjee/cd4f346fac67eb34a47567c330017069 to your computer and use it in GitHub Desktop.
Save akhileshdarjee/cd4f346fac67eb34a47567c330017069 to your computer and use it in GitHub Desktop.
Back to Top Responsive HTML button
<!DOCTYPE html>
<html lang="en">
<head>
<style type="text/css">
a.back-to-top {
display: none;
text-align: center;
line-height: 50px;
width: 50px;
height: 50px;
position: fixed;
z-index: 999;
right: 20px;
bottom: 20px;
background-color: #1ab394;
color: #fff;
border-radius: 3px;
}
a.back-to-top:hover {
color: #fff;
}
</style>
</head>
<body>
<a href="#" class="back-to-top">
<i class="fa fa-chevron-up"></i>
</a>
<script type="text/javascript">
$( document ).ready(function() {
// back to top
var amountScrolled = 300;
$(window).scroll(function() {
if ($(window).scrollTop() > amountScrolled) {
$('a.back-to-top').fadeIn('slow');
}
else {
$('a.back-to-top').fadeOut('slow');
}
});
$('a.back-to-top').click(function() {
$('body, html').animate({
scrollTop: 0
}, 400);
return false;
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment