jq实现回到顶部

保存一个js文件,然后导入


;(function($){
    $.fn.extend({
        backtotop:function(){
            var back_to_top=$('<div>');
            back_to_top.attr('style','display: block;width: 38px;height: 38px;background-color: #ddd;border-radius: 3px;border: 0;cursor: pointer;position: relative;text-align: center;');
            var arrow=$('<div>');
            var stick=$('<div>');
            arrow.attr('style','width: 0;height: 0;top: -1px;border: 9px solid transparent;border-bottom-color: #aaa;margin: auto;');
            stick.attr('style','width: 8px;height: 14px;top: 15px;border-radius: 1px;background-color: #aaa;margin: auto;');
            arrow.appendTo(back_to_top);
            stick.appendTo(back_to_top);
            $(this).bind('click',function(){
                $('body,html').animate({scrollTop:0},1000);
            });
            back_to_top.appendTo($(this));
        }
    })
})(jQuery);

回到顶部 js 插件

html:

<div class='back_to_top'></div>

js:

$('.back_to_top').backtotop();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值