張慧的博客

          張慧的博客

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            45 Posts :: 0 Stories :: 24 Comments :: 0 Trackbacks
          自己寫了一個基于jquery的返回頁面頂端的組件。 
          (function($) { 
          var g; 
          $.backtop = function(options) { 
          extend($.backtop.config, options); 
          this.config = $.backtop.config; 
          this.init(); 
          g = this; 
          }; 
          $.backtop.config = { 
          title : null,// 返回頂端文字說明 
          df_color : "#77AA55"http:// 組件默認顏色 
          }; 
          $.backtop.prototype = { 
          config : null, 
          backtop : null,// 當前創建返回頂端對象 
          init : function() { 
          this._scrool(); 
          }, 
          _scrool : function() { 
          window.onscroll = function() { 
          g._create_ob($(window).scrollTop()); 
          }; 
          }, 
          _create_ob : function(top) { 
          if(top==0){ 
          $("#back_top").remove(); 
          return; 

          $("#back_top").remove(); 
          this.backtop = $("<div class='mouseover'><img src='ui/main/gotop.gif'></img></div>"); 
          $(this.backtop).bind("click",function(){ 
          g._moveTo(); 
          }); 
          $(this.backtop).bind("mouseover",function(){ 
          $(g.backtop).removeClass(); 
          $(g.backtop).addClass("mouse"); 
          }); 
          $(this.backtop).bind("mouseout",function(){ 
          $(g.backtop).removeClass(); 
          $(g.backtop).addClass("mouseover"); 
          }); 
          $(this.backtop).attr("id","back_top"); 
          /*$(this.backtop).css("backgroundColor", this.config.df_color);*/ 
          $(this.backtop).css("zIndex", 1000); 
          $(this.backtop).css("position", "absolute"); 
          $(this.backtop).css("cursor","pointer"); 
          $(this.backtop).width(30); 
          $(this.backtop).height(30); 
          $(this.backtop).css("left",$("body").attr("clientWidth")-50); 
          $(this.backtop).css("top", top+300); 
          $("body").append(this.backtop); 
          },// 創建返回頂端jquery對象 
          _moveTo:function(){ 
          $("#back_top").remove(); 
          window.scroll(0,0); 

          }; 
          })(jQuery); 
          var extend = function($cf, options) { 
          for ( var a in options) { 
          $cf[a] = options[a]; 

          }; 
          posted on 2012-07-12 22:22 張慧 閱讀(755) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 河津市| 揭阳市| 霍邱县| 长沙市| 桐乡市| 施甸县| 泰顺县| 兰考县| 崇阳县| 固始县| 西华县| 信阳市| 太仓市| 肇州县| 宁武县| 万全县| 五莲县| 翁牛特旗| 嘉兴市| 灵丘县| 固原市| 封开县| 曲阜市| 郓城县| 浦北县| 山东省| 高碑店市| 镇雄县| 长兴县| 比如县| 章丘市| 鹤庆县| 汽车| 肃宁县| 彭州市| 安康市| 壶关县| 滨海县| 安丘市| 武平县| 德清县|