Skip to content

Instantly share code, notes, and snippets.

@haitaoyao
Last active September 20, 2019 09:17
Show Gist options
  • Save haitaoyao/887ad489f136d16c124761f7d8a8a2d4 to your computer and use it in GitHub Desktop.
Save haitaoyao/887ad489f136d16c124761f7d8a8a2d4 to your computer and use it in GitHub Desktop.
bootstrap 回到顶部
<style>
.back-to-top {
cursor: pointer;
position: fixed;
bottom: 20px;
right: 20px;
display:none;
}
</style>
<script language="JavaScript">
$(document).ready(function(){
$(window).scroll(function () {
if ($(this).scrollTop() > 50) {
$('#back-to-top').fadeIn();
} else {
$('#back-to-top').fadeOut();
}
});
// scroll body to 0px on click
$('#back-to-top').click(function () {
$('#back-to-top').tooltip('hide');
$('body,html').animate({
scrollTop: 0
}, 800);
return false;
});
$('#back-to-top').tooltip('show');
});
</script>
<a id="back-to-top" href="#" class="btn btn-primary btn-lg back-to-top" role="button" title="Click to return on the top page" data-toggle="tooltip" data-placement="left"><span class="glyphicon glyphicon-chevron-up"></span></a>
@LiLiKiLL
Copy link

LiLiKiLL commented Jul 2, 2017

very nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment