123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <!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>
- .div1{
- width: 300px;
- height: 100px;
- border:5px solid green;
- overflow:scroll;
- }
- .div2{
- width: 1000px;
- height: 100px;
- background-image: linear-gradient( to right,red,blue);
- }
- ::-webkit-scrollbar{
- display: none;
- width: 0;
- height: 0;
- }
- .box{
- width: 100px;
- height: 1000px;
- background-image: linear-gradient(to bottom,red,green);
- }
- </style>
- </head>
- <body>
- <div class="div1">
- <div class="div2"></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>
- </html>
|