jquery 返回頂端組件

來源:互聯網
上載者:User

標籤:style   blog   io   color   os   ar   for   sp   div   

自己寫了一個基於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"// 組件預設顏色 }; $.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]; } }; 

 

jquery 返回頂端組件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.