您的位置:首页 > Web前端 > JavaScript

DOMMouseScroll,onmousewheel 鼠标滚动事件js

2017-02-20 23:07 561 查看
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
div[class^='div'] {
font-family: "微软雅黑";
font-size: 40px;
height: 540px;
border-bottom: solid 1px paleturquoise;
}

.div0 {
background-color: #ff0;
}

.div1 {
background-color: royalblue;
}

.div3 {
background-color: cornflowerblue;
}

.div4 {
background-color: blueviolet;
}
</style>
</head>

<body>
<div class="div0">div0</div>
<div class="div1">div1</div>
<div class="div2">div2</div>
<div class="div3">div3</div>
<div class="div4">div4</div>
</body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
//判断是否是火狐浏览器
var IsFirefox = navigator.userAgent.toLocaleLowerCase().indexOf('firefox') > -1
$(function() {
//添加鼠标滚动的监听事件
if(IsFirefox) {
document.body.addEventListener('DOMMouseScroll', function(event) {
console.log(event.detail); //向上滚动为120,向下是-120
})
} else {
document.body.onmousewheel = function() {
console.log(event.wheelDelta); //向上滚动为120,向下是-120
};
}
})
</script>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: