如何规范Firefox
中的窗口滚动事件?
此浏览器在mousewheel
和Chrome
浏览器中的Safari
上可以正常工作,但在Firefox
浏览器中不能正常工作
var normalizeWheelEvent = function(event) {
if (!!event.wheelDelta) {
var wheelDeltaRate = 10;
event.wheelX = event.wheelDeltaX / wheelDeltaRate;
event.wheelY = event.wheelDeltaY / wheelDeltaRate;
}
};
target.addEventListener('mousewheel',normalizeWheelEvent, useCapture);
如何在Firefox中更新event
以规范mousewheel
?
答案 0 :(得分:0)
对于Firefox,您需要使用e.detail
,如下所示:
if (!!event.detail) {
// Similar to your wheelDeltaRate, detailRate will change the speed
var detailRate = 1.20;
// let's add some magic for scrolling
event.wheelX = event.axis == event.HORIZONTAL_AXIS ? (-1 * event.detail) * detailRate : 0;
event.wheelY = event.axis == event.VERTICAL_AXIS ? (-1 * event.detail) * detailRate : 0;
}
不要忘记使用:
target.addEventListener('DOMMouseScroll',normalizeWheelEvent, useCapture);
让我知道它是否对您有用