jquery返回頂部,支援手機

來源:互聯網
上載者:User

標籤:

jquery返回頂部,支援手機

效果體驗:http://hovertree.com/texiao/mobile/6/

在pc上我們很容易就可以用scrollTop()來實現流程的向上滾動的返回到頂部的動畫,然後用到web移動端卻沒什麼卵用,會出現滾動不流暢,卡頓,失靈等等現象。

這是因為移動端的scroll事件觸發不頻繁,有可能檢測不到有<=0的情況


為此,移動端判斷次數好些,下面是具體實現代碼,相容pc:

<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>    <title>移動端返回頂部 - 何問起</title><base target="_blank" />    <meta name="viewport" content="width=device-width, initial-scale=1" />    <meta charset="utf-8" />    <style>        #tophovertree{display:block;position:fixed;width:36px;height:36px;right:20px;bottom:20px;cursor:pointer;background-image:url(http://hovertree.com/texiao/mobile/6/tophovertree.gif);opacity:0.9;display:none}        a{color:blue}    </style>    <script src="http://hovertree.com/ziyuan/jquery/jquery-1.11.3.min.js"></script></head><body>    <div style="height:500px;width:100%;">1    <br />請向下滾動頁碼,你將會看到返回頂部的按鈕。<br />    <a href="http://hovertree.com/h/bjae/ve3erni6.htm">原文</a> <a href="http://hovertree.com">首頁</a> <a href="http://hovertree.com/menu/jquery/">jQuery</a>  <a href="http://hovertree.com/texiao/">特效</a>        <br />  <script type="text/javascript" src="/themes/sy/gggg728x90a.js"></script>    </div>    <div style="height:500px;width:100%;">2何問起</div>    <div style="height:500px;width:100%;">3</div>    <div style="height:500px;width:100%;">4</div>    <div style="height:500px;width:100%;">5</div>    <div style="height:500px;width:100%;">6 柯樂義</div>    <div style="height:500px;width:100%;">7</div>    <div style="height:500px;width:100%;">8 keleyi</div>    <div style="height:500px;width:100%;">9</div>    <span id="tophovertree" title="返回頂部"></span>    <script src="http://hovertree.com/texiao/mobile/6/topHovertree.js"></script>    <script>    $(function () { initTopHoverTree("tophov"+"ertree",500,30,20); })    </script></body></html>

更多: http://www.cnblogs.com/jihua/p/webfront.html

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.