zoukankan      html  css  js  c++  java
  • 回到顶部插件

     1 <script src="jquery-1.11.3.min.js"></script>
     2 <script>
     3 (function($){
     4     function Obj(element,options){
     5         this.element = element;
     6         this.defaults = {
     7             time:30,
     8             speed:8,
     9             scrollTop:100
    10         };
    11         this.options = $.extend({},this.defaults,options)
    12      }
    13      Obj.prototype.toTop = function(){
    14           var options = $.extend({},this.defaults,options);
    15           var timer = null;
    16           $("body").append($("<span id='toTop' style='position: fixed; 54px;height: 54px;bottom: 50px;right: 70px;cursor: pointer;background: red; z-Index: 101;display:none'></span>"));
    17           $("#toTop").bind("click",function(){ 
    18                clearInterval(timer);
    19                timer = setInterval(function(){
    20                  var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    21                  var iSpeed = Math.floor(0-scrollTop/options.speed);
    22                  document.documentElement.scrollTop = document.body.scrollTop = scrollTop + iSpeed;
    23                  if(scrollTop == 0){
    24                     clearInterval(timer);
    25                   } 
    26                     },options.time);
    27                });
    28           return this;
    29      };
    30      Obj.prototype.scroll = function(){
    31          var options = $.extend({},this.defaults,options);
    32          this.element.bind("scroll",function(){
    33              var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    34              if(scrollTop>=options.scrollTop){
    35                   $("#toTop").fadeIn(); 
    36               }else{
    37                   $("#toTop").fadeOut();
    38               }
    39          })
    40          return this;
    41      }
    42     $.prototype.extend({
    43          "toTop":function(options){
    44             var toTop = new Obj(this,options);
    45             return toTop.toTop()
    46          },
    47          "scroll":function(options){
    48             var scroll = new Obj(this,options);
    49             return scroll.scroll()
    50          }
    51     })
    52 })(jQuery)
    53 
    54 $(function(){
    55   $("#toTop").toTop({
    56      time:30,
    57      speed:8
    58   });
    59   $(window).scroll({
    60     scrollTop:100
    61   });
    62 })
    63 </script>
  • 相关阅读:
    hdu 1241 Oil Deposits(dfs入门)
    hdu 1022 Train Problem I(栈)
    DFS中的奇偶剪枝(转自chyshnu)
    ural 1821. Biathlon
    hdu 1237 简单计算器(栈)
    hdu 1010 Tempter of the Bone(dfs+奇偶剪枝)
    1119. Metro(动态规划,滚动数组)
    hdu 1312 Red and Black(dfs入门)
    C#匿名委托和匿名方法使用小技巧
    ubuntu下netbeans乱码问题解决
  • 原文地址:https://www.cnblogs.com/studyshufei/p/9023817.html
Copyright © 2011-2022 走看看