原生js鼠标滑动滚轮事件

var agent = navigator.userAgent;
if(/.*Firefox.*/.test(agent)) {
document.addEventListener("DOMMouseScroll", function(e) {
e = e || window.event;
var detail = e.detail;
if(detail > 0) {
var input = document.getElementById("input");
input.blur();
} else {
console.warn("鼠标向上滚动");
}
});
} else {
document.onmousewheel = function(e) {
e = e || window.event;
var wheelDelta = e.wheelDelta;
if(wheelDelta > 0) {
var input = document.getElementById("input");
input.blur();
} else {
var input = document.getElementById("input");
input.blur();
}
}
}

posted @ 2018-06-12 17:39  印度阿铭  阅读(2231)  评论(0编辑  收藏  举报