OSX inertia scrolling causing mousewheel.js to register multiple mousewheel events with the slightest scroll motion

别说谁变了你拦得住时间么 提交于 2019-12-03 16:20:09
Jon Smock

I think the main problem is that you won't be able to apply debouncing as an after effect, or at least I wouldn't know how. Let's talk through how the pieces work:

When you call $('div.flexslider').flexslider({ .. }, jQuery finds all the elements like div.flexslider (as usual) and then adds a flexslider to that. flexslider adds all the machinery to make it a slider, including setting up bind events. It's the actual bind events themselves that you need to debounce.

Seems like you got pretty close by finding the relevant flexslider bind code. I think what you'd want ideally is this:

if (vars.mousewheel) {
  slider.bind('mouse wheel', _.debounce(function(…) {
   // usual flex slider code.
  }), 300);
}

I'm not sure how you'd actually inject this debounce without directly editing the flexslider code.

You probably could debounce the mouse wheel plugin itself, if you want to globally affect mousewheel events (which I guess you might). I think you'd have to wrap the handler in a debounce, and then pass the debounced-handler to the addEventListener and removeEventListener.

Looks like this problem still exists.

I've got some good results using this debounce plugin and changing flexslider.js so it's the folllowing:

slider.bind('mousewheel', $.debounce( 100, true, function(event, delta, deltaX, deltaY){
     event.preventDefault();
     var target = (delta < 0) ? slider.getTarget('next') : slider.getTarget('prev');

    slider.flexAnimate(target, slider.vars.pauseOnAction);
}));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!