Last active
August 29, 2015 14:17
-
-
Save fnnzzz/94f53e215794bec0ab42 to your computer and use it in GitHub Desktop.
toUp button
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
var top_show = 350; // В каком положении полосы прокрутки начинать показ кнопки "Наверх" | |
var delay = 1000; // Задержка прокрутки | |
$(document).ready(function() { | |
$(window).scroll(function () { // При прокрутке попадаем в эту функцию | |
/* В зависимости от положения полосы прокрукти и значения top_show, скрываем или открываем кнопку "Наверх" */ | |
if ($(this).scrollTop() > top_show) $('#top').fadeIn(); | |
else $('#top').fadeOut(); | |
}); | |
$('#top').click(function () { // При клике по кнопке "Наверх" попадаем в эту функцию | |
/* Плавная прокрутка наверх */ | |
$('body, html').animate({ | |
scrollTop: 0 | |
}, delay); | |
}); | |
}); | |
#top { | |
bottom: 1em; | |
right: 1em; | |
cursor: pointer; | |
display: none; | |
font-size: 2em; | |
position: fixed; | |
z-index: 10000; | |
} | |
<div id="top"><i class="fa fa-chevron-circle-up"></i></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment