- js实现顶部悬浮、一键回到顶部,代码中有详细注释。。
效果图:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/1a4c0bb17aff009c712928c454827ba6.gif)
html、css 代码实现:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
padding: 0;
margin: 0;
font-size: 42px;
text-align: center;
color: #fff;
}
.header {
width: 100%;
height: 100px;
background-color: burlywood;
}
.nav {
width: 100%;
height: 150px;
background-color: cadetblue;
}
.main {
width: 100%;
height: 1000px;
background-color: cornflowerblue;
}
.bottom {
width: 100%;
height: 200px;
background-color: palevioletred;
}
#topBtn {
width: 60px;
font-size: 42px;
position: fixed;