运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <head> <style> div { background-color: lightblue; height: 2000px; width: 2000px; } </style> </head> <body> <h1>The Window Object</h1> <h2>The scrollX and scrollY Properties</h2> <p>Click the button to scroll the document window 100px horizontally and vertically.</p> <button onclick="myFunction()" style="position:fixed;">Click me to scroll</button><br><br> <div></div> <script> function myFunction() { window.scrollBy(100, 100); alert("pageXOffset: " + window.scrollX + ", scrollY: " + window.scrollY); } </script> </body> </html>