html css jquery 回到頂部按鈕

來源:互聯網
上載者:User

標籤:span   click   class   項目   back   pointer   移動   index   one   

今天做了個回到頂部的功能,在這裡記錄一下,有需要可以拿去試試!

CSS部分,很簡單就一個class

        /*回到頂部*/        .back-top        {            position: fixed;            right: 15px;            bottom: 15px;            z-index: 9999;            font-size: 25px;            width: 40px;            height: 40px;            background-color: #adadad;            color: #ffffff;            cursor: pointer;            border-radius: 2px;            text-align: center;        }        .back-top:hover        {            background-color: #a3a3a3;        }

html部分 也非常簡單,一個div, 裡面一個表徵圖就可以了.表徵圖我是用奧森表徵圖,大家可以自行更換

<div class="back-top" style="display: none;" title="回到頂部">        <!--此處回到頂部表徵圖自己改-->        <i class="fa fa-angle-double-up"></i>    </div>

 

jQuery 部分,也非常簡單,相關注意點看注釋

        //回到頂部        $(function () {            if ($(window).width() >= 700) {//本人的項目是響應式的,但是移動端不顯示回到頂部,自己可以去掉                $(window).scroll(function () {                    if ($(window).scrollTop() <= 200) {                        if ($(".back-top").css("display") != "none") {                            $(".back-top").slideUp("normal"); //緩慢下降隱藏                        }                    }                    else {                        if ($(".back-top").css("display") == "none") {                            $(".back-top").slideDown("normal"); //緩慢上升顯示                        }                    }                });            }        });        $(".back-top").click(function () {            $("body").animate({ scrollTop: 0 }, "slow"); //回到頂部        });

 

html css 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.