实现方法一:
<footer>
<p class="ft-copyright">强仔仔 Design by Linzhiqaing 蜀ICP备11002373号-1</p>
<div id="tbox">
<div id="log_id" style="float:left;position: relative;margin-left: -400px;margin-bottom:-5px;display: none">
<img src="images/weixing-ma.jpg">
</div>
<div style="float:right;"><a id="togbook" href="#顶部的一个ID"></a></div>
<div style="float:left"><a id="gotop"></a></div>
</div>
</footer>
这第一个方法比较简单,就是在超链接中写上“#顶部的ID”就可以实现回到顶部的功能了,不过如果是这种方法的话就不会出现那种滑动的效果,交互性不太好。
下面在介绍一种可以实现滑动的回到顶部功能,并且可以自己设置滑动的速度和回到顶部的位置等。推荐大家用这种模式实现回到顶部的功能,下面来实现的例子。
实现方法二:
<footer>
<p class="ft-copyright">强仔仔 Design by Linzhiqaing 蜀ICP备11002373号-1</p>
<div id="tbox">
<div id="log_id" style="float:left;position: relative;margin-left: -400px;margin-bottom:-5px;display: none">
<img src="images/weixing-ma.jpg">
</div>
<div style="float:right;"><a id="togbook" href="#"></a></div>
<div style="float:left"><a id="gotop"></a></div>
</div>
</footer>
<script type="text/javascript">
$("#gotop").click(function () {
var speed=200;//滑动的速度
$('body,html').animate({ scrollTop: 0 }, speed);
return false;
});
</script>
通过写一段js代码就可以实现回到顶部的功能了,是不是特别简单啊。
如对内容有问题或有疑义,请及时提出,不甚感谢。本人QQ:208017534
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有