Skip to content

Instantly share code, notes, and snippets.

@Padilo300
Created February 19, 2018 20:11
Show Gist options
  • Save Padilo300/fc6e18528b6fbc54b57ee2677492c357 to your computer and use it in GitHub Desktop.
Save Padilo300/fc6e18528b6fbc54b57ee2677492c357 to your computer and use it in GitHub Desktop.
Кнопка прокрутки страницы вверх.
.text-block {
width: 250px;
margin: 50px;
}
#go-top {
position: fixed;
bottom: 25px;
right: 70px;
text-align: center;
cursor:pointer;
display:none;
width: 80px;
height: 30px;
background: #c0c0c0;
line-height: 30px;
border-radius: 5px;
}
$(document).ready(function(){
$('body').append('<a href="#" id="go-top" title="Вверх">Вверх</a>');
});
$(function() {
$.fn.scrollToTop = function() {
$(this).hide().removeAttr("href");
if ($(window).scrollTop() >= "250") $(this).fadeIn("slow")
var scrollDiv = $(this);
$(window).scroll(function() {
if ($(window).scrollTop() <= "250") $(scrollDiv).fadeOut("slow")
else $(scrollDiv).fadeIn("slow")
});
$(this).click(function() {
$("html, body").animate({scrollTop: 0}, "slow")
})
}
});
$(function() {
$("#go-top").scrollToTop();
});
@Padilo300
Copy link
Author

Не требует HTML.
Плавно появляется и исчезает.

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