<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>卡通火箭返回顶部</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
#rocket-to-top {
position: fixed;
right: 30px;
bottom: 50px;
width: 60px;
height: 90px;
cursor: pointer;
z-index: 999;
display: none;
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 90"><path d="M30 0 L60 60 L30 45 L0 60 Z" fill="%23FF6B6B"/><path d="M25 45 L35 45 L35 90 L25 90 Z" fill="%234ECDC4"/><circle cx="30" cy="30" r="10" fill="%23FFE66D"/><path d="M20 25 L40 25 L35 40 L25 40 Z" fill="%23FF9F1C"/></svg>') no-repeat;
transition: all 0.3s;
}
#rocket-to-top:hover {
transform: translateY(-5px);
}
.footer {
text-align: center;
padding: 20px;
margin-top: 1000px;
font-size: 12px;
color: #999;
}
</style>
</head>
<body>
<div id="rocket-to-top" title="返回顶部"></div>
<div class="content">
<!-- 页面内容 -->
<h1>向下滚动查看返回顶部火箭</h1>
<p>滚动页面后,右下角会出现一个卡通火箭,点击它可以返回顶部。</p>
</div>
<div class="footer">
</div>
<script>
$(document).ready(function() {
// 显示/隐藏火箭
$(window).scroll(function() {
if ($(this).scrollTop() > 200) {
$('#rocket-to-top').fadeIn();
} else {
$('#rocket-to-top').fadeOut();
}
});
// 点击火箭返回顶部
$('#rocket-to-top').click(function() {
$('html, body').animate({scrollTop: 0}, 800);
return false;
});
// 火箭发射动画
$('#rocket-to-top').hover(
function() {
$(this).css('background-position', '0 -90px');
},
function() {
$(this).css('background-position', '0 0');
}
);
});
</script>
</body>
</html>
2837

被折叠的 条评论
为什么被折叠?



