web前端全系列 教程
1839个小节阅读:2242.9k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
xxxxxxxxxx
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./js/jquery-3.6.0.min.js"></script>
<style>
div {
height: 500px;
}
#btn {
width: 35px;
height: 45px;
position: fixed;
right: 50px;
bottom: 50px;
background: #333;
text-decoration: none;
color: #fff;
text-align: center;
padding: 10px;
display: none;
}
</style>
</head>
<body>
<div>内容1</div>
<div>内容2</div>
<div>内容3</div>
<div>内容4</div>
<div>内容5</div>
<div>内容6</div>
<!-- 让a标签失去href属性的效果 -->
<a href="javaScript:void(0)" id="btn">回到顶部</a>
<script>
//当滚动条的位置处于距顶部50像素以下时,跳转链接出现,否则消失
$(function () {
$(window).scroll(function () {
if ($(window).scrollTop() > 500) {
$("#btn").fadeIn(200);
} else {
$("#btn").fadeOut(200);
}
});
//当点击跳转链接后,回到页面顶部位置
$("#btn").click(function () {
$('body,html').animate({
scrollTop: 0
},500);
});
});
</script>
</body>
</html>