js如何判断鼠标滚轮是向下还是向上滚动
1个回答
展开全部
<!DOCTYPE HTML>
<html>
<head>
<meta charset=utf-8>
<title>yugi</title>
<style>
body{
height: 1111px;
}
</style>
<script>
var agent = navigator.userAgent;
if (/.*Firefox.*/.test(agent)) {
document.addEventListener("DOMMouseScroll", function(e) {
e = e || window.event;
var detail = e.detail;
if (detail > 0) {
console.log("鼠标向下滚动");
} else {
console.warn("鼠标向上滚动");
}
});
} else {
document.onmousewheel = function(e) {
e = e || window.event;
var wheelDelta = e.wheelDelta;
if (wheelDelta > 0) {
console.log("鼠标向上滚动");
} else {
console.warn("鼠标向下滚动");
}
}
}
</script>
</head>
<body>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询