jquery右下角返回頂部

來源:互聯網
上載者:User

標籤:

實現的效果也就是,當有捲軸是,捲軸未動或與頂部距離小於多少像素是,返回頂部按鈕處於隱藏狀態,當捲軸與頂部距離大於一定像素時,返回頂部按鈕出現,實現點擊‘返回按鈕’後,從當前位置回到等不位置。要先引用jquery.min.js

<script src="__PUBLIC__/js/jquery-2.1.4.min.js"></script>

 

html:

<div id="back-to-top" style="display:none">返<br />回<br />頂<br />部</div>

css:

  #back-to-top{       width: 25px;position:fixed;bottom:20px;right:20px;border:solid 1px #ccc;cursor:pointer;text-align: center;color: red;        _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));        }

js:

jQuery(function ($) {            //當捲軸的位置處於距頂部20像素以下時,跳轉連結出現,否則消失                $(window).scroll(function(){                    if (jQuery(window).scrollTop()>20){                        jQuery("#back-to-top").fadeIn(1000);                    }                    else                    {                        jQuery("#back-to-top").fadeOut(1000);                    }                });                    //當點擊跳轉連結後,回到頁面頂部位置                    jQuery("#back-to-top").click(function(){                    jQuery(‘body,html‘).animate({scrollTop:0},1000);                    return false;                });        }); 

 

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.