Back To Top

 1 //scroll to top
 2 (function ($) {
 3     $.fn.backTop = function () {
 4         var backBtn = this;
 5 
 6         var position = 1000;
 7         var speed = 900;
 8 
 9         $(document).scroll(function () {
10             var pos = $(window).scrollTop();
11 
12             if (pos >= position) {
13                 backBtn.fadeIn(speed);
14             } else {
15                 backBtn.fadeOut(speed);
16             }
17         });
18 
19         backBtn.click(function () {
20             $("html, body").animate({ scrollTop: 0 }, 900);
21         });
22     }
23 }(jQuery));

HTML

 <a id="backTop" class="btn btn-back-top bg-teal"></a>
1 $(document).ready(function () {
2     $('#backTop').backTop();
3  });
View Code

 

 

posted @ 2019-04-13 09:50  mantishell  阅读(242)  评论(0编辑  收藏  举报