Last active
March 29, 2017 21:09
-
-
Save kas-cor/ee78307c4a8d433138f8162a38ef5d8d to your computer and use it in GitHub Desktop.
Кнопка back to top или scroll to top
This file contains hidden or 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
| window.jQuery || document.write('<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>'); | |
| document.addEventListener("DOMContentLoaded", function () { | |
| $(function () { | |
| var elem = "scroll-to-top"; // id object | |
| var img = "//path/to/img/file.png"; // url to img | |
| var obj; | |
| $("body").append('<div id="' + elem + '"></div>'); | |
| obj = $("#" + elem); | |
| $(obj).css({ | |
| "display": "none", | |
| "background": "url('" + img + "') no-repeat", | |
| "background-size": "contain", | |
| "position": "fixed", | |
| "right": "20px", | |
| "bottom": "80px", | |
| "height": "60px", | |
| "width": "60px", | |
| "opacity": ".9", | |
| "cursor": "pointer" | |
| }); | |
| $(window).scroll(function () { | |
| if ($(this).scrollTop() > 20) { | |
| $(obj).stop(true).fadeIn(); | |
| } else { | |
| $(obj).stop(true).fadeOut(); | |
| } | |
| }); | |
| $(obj).click(function () { | |
| $("body, html").stop(true).animate({scrollTop: 0}, 600); | |
| return false; | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Установка
Перед закрывающем тегом
</body>, вставляем стоку:Параметры
Переменные:
elem- id контейнера кнопки (изменяется если уже занят)img- Путь до изображения кнопки (стрелки)Положение и размер: