Created
February 19, 2018 20:11
-
-
Save Padilo300/fc6e18528b6fbc54b57ee2677492c357 to your computer and use it in GitHub Desktop.
Кнопка прокрутки страницы вверх.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Не требует HTML.
Плавно появляется и исчезает.