Skip to content

Instantly share code, notes, and snippets.

@bxtimur
Created February 23, 2018 08:02
Show Gist options
  • Save bxtimur/c528b1d1fbd9ca6d56de3d38b16d4151 to your computer and use it in GitHub Desktop.
Save bxtimur/c528b1d1fbd9ca6d56de3d38b16d4151 to your computer and use it in GitHub Desktop.
Кнопка прокрутки наверх
<div class="scroll-up" style="display: block;"></div>
<style>
.scroll-up {
width: 45px;
height: 45px;
border-radius: 25px;
background: #fb5f41;
position: fixed;
z-index: 9999;
bottom: 20px;
left: 25px;
cursor: pointer;
opacity: 0.8;
}
.scroll-up:hover {
opacity: 1;
}
.scroll-up:after {
content: "";
width: 7px;
height: 7px;
border: solid 2px #ffffff;
position: absolute;
right: 0;
left: 0;
top: 0;
bottom: 0;
margin: auto;
transform: rotate(-45deg);
border-left: none;
border-bottom: none;
z-index: 2;
}
</style>
<script>
$(function(){
$.fn.liScrollToTop = function(params){
return this.each(function(){
var scrollUp = $(this);
scrollUp.hide();
if ($(window).scrollTop() > 0) scrollUp.fadeIn("slow")
$(window).scroll(function() {
if ($(window).scrollTop() <= 0) scrollUp.fadeOut("slow")
else scrollUp.fadeIn("slow")
});
scrollUp.click(function() {
$("html, body").animate({scrollTop: 0}, "slow")
})
});
};
$('.scroll-up').liScrollToTop();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment