问题
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