jquery返回頂部,支持手機


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM