<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
height: 3000px;
}
</style>
</head>
<body>
<script>
// document.documentElement.scrollTop滚动距离
window.onscroll = function(){
// 兼容性
console.log(document.documentElement.scrollTop || document.body.scrollTop)
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
height: 3000px;
width: 3000px;
}
</style>
</head>
<body>
<script>
// 横向滚动
console.log(document.documentElement.scrollLeft || document.body.scrollLeft)
</script>
</body>
</html>