張慧的博客

          張慧的博客

            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)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 平南县| 青川县| 平邑县| 喜德县| 嘉义市| 错那县| 凤台县| 冷水江市| 金山区| 兴山县| 紫阳县| 天峻县| 务川| 商都县| 张家川| 永康市| 青田县| 固阳县| 嘉荫县| 榆树市| 贵定县| 盐亭县| 蛟河市| 墨脱县| 遂平县| 聂拉木县| 云龙县| 辽阳县| 栾川县| 临泉县| 双柏县| 含山县| 宜章县| 乌苏市| 东台市| 盐边县| 扶绥县| 城步| 湟中县| 新闻| 霍林郭勒市|