html页面刷新回到顶部_html页面滚动到一定位置显示回到顶部按钮

这段代码实现了一个固定在右下角的悬浮按钮,按钮有两种样式,一种是支持图标,一种是火箭图标。当页面滚动超过100像素时,悬浮按钮会淡入显示,点击按钮可以快速返回页面顶部。该功能通过jQuery实现,利用了CSS3的过渡效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

.t-right-bar {

position: fixed;

right: 0;

bottom: 10%;

width: 48px;

height: 48px;

z-index: 1000;

cursor: pointer;

}

.t-right-bar > div {

float: left;

height: 36px;

margin-bottom: 1px;

border-radius: 20px 0 0 20px;

color: #fff;

padding-left: 100%;

clear: both;

white-space: nowrap;

font-size: 13px;

line-height: 36px;

font-style: normal;

background-color: #aaa;

background-repeat: no-repeat;

background-position: 12px center;

transition: transform .2s cubic-bezier(.215, .61, .355, 1), padding .2s cubic-bezier(.215, .61, .355, 1), margin .2s cubic-bezier(.215, .61, .355, 1), background-color .2s cubic-bezier(.215, .61, .355, 1)

}

.t-right-bar > div.active, .t-right-bar > div:hover {

transform: translateX(-100%);

padding-left: 45px;

padding-right: 10px;

margin-left: 48px;

background-color: #23a0e1;

text-decoration: none;

color: #fff

}

.t-right-bar .t-bar-support {

background-image: url(../img/icon/support_1.svg); //按钮图标

background-position: 14px center;

}

.t-right-bar .t-bar-rocket {

background-image: url(../img/icon/rocket_1.svg); //按钮图标

background-position: 19px center;

}

.t-bar-support a{

color: white;

}

.t-bar-support a:hover{

color: #fff

}

$(".t-right-bar").hide();

$(function () {

$(window).scroll(function () {

if ($(window).scrollTop() > 100) {

$(".t-right-bar").fadeIn(500);

}

else {

$(".t-right-bar").fadeOut(500);

}

});

$("#back-to-top").click(function () {

$('body,html').animate({scrollTop: 0}, 100);

return false;

});

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值