监听网页滚动条向上向下滚动

Posted duguangyan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了监听网页滚动条向上向下滚动相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title></title>
<script type="text/javascript">
var scrollFunc = function (e) {
e = e || window.event;
if (e.wheelDelta) { //判断浏览器IE,谷歌滑轮事件
if (e.wheelDelta > 0) { //当滑轮向上滚动时
alert("滑轮向上滚动");
}
if (e.wheelDelta < 0) { //当滑轮向下滚动时
alert("滑轮向下滚动");
}
} else if (e.detail) { //Firefox滑轮事件
if (e.detail> 0) { //当滑轮向上滚动时
alert("滑轮向上滚动");
}
if (e.detail< 0) { //当滑轮向下滚动时
alert("滑轮向下滚动");
}
}
}
//给页面绑定滑轮滚动事件
if (document.addEventListener) {//firefox
document.addEventListener(‘DOMMouseScroll‘, scrollFunc, false);
}
//滚动滑轮触发scrollFunc方法 //ie 谷歌
window.onmousewheel = document.onmousewheel = scrollFunc;
</script>
</head>
<body>
<div style="height:2000px;width:200px;background:#333;"></div>
</body>
</html>

以上是关于监听网页滚动条向上向下滚动的主要内容,如果未能解决你的问题,请参考以下文章

JS原生监听滚动条

如何获取网页滚动条滚动事件

Chrome 32 更新中缺少向上/向下滚动条箭头按钮

selenium 如何控制滚动条逐步滚动

Kivy 滚动条滚动方向与鼠标

jQuery控制页面滚动条上下滚动