let wheelCounter = 0;
// Function to handle mouse wheel events
function handleMouseWheel(event) {
// Detect the direction of the mouse wheel
const direction = event.deltaY > 0 ? 'down' : 'up';
// Update the counter based on the direction
if (direction === 'down') {
wheelCounter++;
} else {
wheelCounter--;
}
// Display the current count
console.log(`Mouse wheel turned ${wheelCounter} times`);
}
// Attach the event listener to the document
document.addEventListener('wheel', handleMouseWheel);
3条答案
按热度按时间mwyxok5s1#
你是说像这样的东西:
字符串
http://jsfiddle.net/eHEmr/
(you显然,你可以把自己的代码,而不是
scroll++;
)amrnrhlw2#
原来我真正需要的是找到滚动停止的时间。得到了解决方案here。
字符串
谢谢
qvk1mo1f3#
鼠标滚轮计数器
字符串