我有基于滚动实现的功能。 这是小片段::
$(window).bind('scroll',function(event)
{
console.log(event.type);
//Task to do
}
这里我想区分是通过mouseScroll还是通过拖动滚动来完成绑定。 通过检查event.type,两者都返回“滚动”作为事件类型。
答案 0 :(得分:3)
您可以使用wheel DOM event来检测鼠标滚轮事件:
var isMouseScroll = false;
window.addEventListener('wheel',function(e)
{
console.log('mouse wheel');
isMouseScroll = true;
});
window.addEventListener('scroll',function(e)
{
if(!isMouseScroll) {
console.log('scroll');
}
isMouseScroll = false;
});
注意 - 不要将轮子与已弃用的非标准mousewheel事件混淆。