菜单切换
FACESOHO知行者
心灵
记录
远方
赞赏工具
源代码:
点击运行
保存
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>小鸟启蒙(facesoho.com)</title> <style> div { border:1px solid black; background-color:lightblue; height:2000px; width:2000px; } </style> </head> <body> <p>点击按钮将文档窗口在水平和垂直方向各滚动 100px 。</p> <button onclick="myFunction()" style="position:fixed;">点我滚动</button><br><br> <div> </div> <script> function myFunction() { window.scrollBy(100, 100); if (window.pageXOffset !== undefined) { // 所有浏览器,除了 IE9 及更早版本 alert("水平滚动:" + window.pageXOffset + ", 垂直滚动:" + window.pageYOffset); } else { // IE9 及更早版本 alert("水平滚动:" + document.documentElement.scrollLeft + ", 垂直滚动:" + document.documentElement.scrollTop); } } </script> </body> </html>
运行结果