Can't seem to pass options to Hammer.js Jquery

拥有回忆 提交于 2019-12-13 05:24:31

问题


What am I doing wrong? Can't seem to pass any options to the JQuery plugin of Hammer.js

$('#my-div').hammer({direction: Hammer.DIRECTION_ALL}).bind('pan', function(e){
    // do something
});

I've tried passing "direction" as string too but still no joy - Please help :-(


回答1:


If you're using the jquery.hammer plugin You can access the Hammer.Manager instance on the data object and set options.

In your case:

$('#my-div').data('hammer').get('pan').set({ direction: Hammer.DIRECTION_ALL });



回答2:


From the documentation:

You can setup your own set of recognizers for your instance. This requires a bit more code, but it gives you more control about the gestures that are being recognized.

var mc = new Hammer.Manager(myElement, myOptions);

mc.add( new Hammer.Pan({ direction: Hammer.DIRECTION_ALL, threshold: 0 }) );
mc.add( new Hammer.Tap({ event: 'quadrupletap', taps: 4 }) );

mc.on("pan", handlePan);
mc.on("quadrupletap", handleTaps);


来源:https://stackoverflow.com/questions/25622150/cant-seem-to-pass-options-to-hammer-js-jquery

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