基本信息
源码名称:js监听滚动条 滚动事件
源码大小:0.73KB
文件格式:.zip
开发语言:js
更新时间:2020-10-26
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
<!DOCTYPE html>
<html>
<head>
<title>滚动</title>
<style>
#box{
width: 100%;
height: 2000px;
border: 1px solid green;
}
</style>
</head>
<body style="margin:0px;padding:0px;">
<div id="box"></div>
<script type="text/javascript">
'use strict';
window.onscroll = function() {
//为了保证兼容性,这里取两个值,哪个有值取哪一个
//scrollTop就是触发滚轮事件时滚轮的高度
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
if(scrollTop){
alert("滚动检测成功!");
}
console.log("滚动距离" scrollTop);
}
</script>
</body>
</html>