在jQuery中,可以通过监听mousewheel
事件来判断鼠标开始滚动。以下是一个简单的示例代码,展示了如何使用jQuery来检测鼠标滚动的开始:
$(document).ready(function() {
var scrollTimer = null;
var isScrolling = false;
$(window).on('mousewheel DOMMouseScroll', function(event) {
clearTimeout(scrollTimer);
if (!isScrolling) {
console.log('滚动开始');
isScrolling = true;
}
scrollTimer = setTimeout(function() {
console.log('滚动结束');
isScrolling = false;
}, 100); // 设置一个延迟时间来判断滚动是否结束
});
});
mousewheel
事件。mousewheel
和DOMMouseScroll
事件,可以确保在不同浏览器中都能正常工作。通过这种方式,可以有效地检测鼠标滚动的开始,并根据需要执行相应的操作。