码迷,mamicode.com
首页 > 移动开发 > 详细

jquery返回顶部,支持手机

时间:2015-12-19 23:17:50      阅读:359      评论:0      收藏:0      [点我收藏+]

标签:

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返回顶部,支持手机

标签:

原文地址:http://www.cnblogs.com/jihua/p/totop.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!