|
@@ -21,11 +21,37 @@
|
|
width: 0;
|
|
width: 0;
|
|
height: 0;
|
|
height: 0;
|
|
}
|
|
}
|
|
|
|
+ .box{
|
|
|
|
+ width: 100px;
|
|
|
|
+ height: 1000px;
|
|
|
|
+ background-image: linear-gradient(to bottom,red,green);
|
|
|
|
+ }
|
|
</style>
|
|
</style>
|
|
</head>
|
|
</head>
|
|
<body>
|
|
<body>
|
|
<div class="div1">
|
|
<div class="div1">
|
|
<div class="div2"></div>
|
|
<div class="div2"></div>
|
|
</div>
|
|
</div>
|
|
|
|
+ <div class="box">
|
|
|
|
+
|
|
|
|
+ </div>
|
|
|
|
+ <button onclick="backtop()">返回顶部</button>
|
|
|
|
+ <script>
|
|
|
|
+ window.onscroll = function(){
|
|
|
|
+ // console.log("scroll");
|
|
|
|
+ console.log("滚动距离顶部距离",document.documentElement.scrollTop);
|
|
|
|
+ console.log("可滚动区域高度",document.documentElement.scrollHeight);
|
|
|
|
+ console.log("视口高度",document.documentElement.clientHeight);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ function backtop(){
|
|
|
|
+ console.log("com")
|
|
|
|
+ // window.scrollTo(0,0)
|
|
|
|
+ window.scrollTo({
|
|
|
|
+ top:0,
|
|
|
|
+ behavior:"smooth"
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ </script>
|
|
</body>
|
|
</body>
|
|
</html>
|
|
</html>
|