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>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· Windows编程----内核对象竟然如此简单?
2012-12-19 jQuery实现可拖动的浮动层(版本2)