返回顶部demo

一、html 页面代码如下

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>返回顶部demo</title>
    <style>
        .to-top { display: none; padding: 10px;  color: #fff; background-color: #f50;}
    </style>
</head>
<body style="height: 111110px;width:800px;border:  1px dashed black;">

<a class="to-top">TOP</a>
<script type="text/javascript" src="./jquery.min.js"></script>
<script type="text/javascript" src="./jquery.toTop.min.js"></script>
</body>
</html>


二、jquery.toTop.min.js 代码如下:


!function(o){o.fn.toTop=function(t){var i=this,e=o(window),s=o("html, body"),n=o.extend({autohide:!0,offset:420,speed:500,position:!0,right:15,bottom:30},t);i.css({cursor:"pointer"}),n.autohide&&i.css("display","none"),n.position&&i.css({position:"fixed",right:n.right,bottom:n.bottom}),i.click(function(){s.animate({scrollTop:0},n.speed)}),e.scroll(function(){var o=e.scrollTop();n.autohide&&(o>n.offset?i.fadeIn(n.speed):i.fadeOut(n.speed))})}}(jQuery);$(function(){ $('.to-top').toTop({ autohide: true,offset: 1,speed: 100,position: true,right: 10,bottom: 10 });})

最后的效果:
在这里插入图片描述

使用的插件的GitHub 地址:https://github.com/mmkjony/jQuery.toTop

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值