Open alwerner opened 9 years ago
Hammer.JS - v2.0.2
//Swipe event listeners with actions if($('.slider').length){ myElement = $('.slider').get(0); mc = new Hammer(myElement); // listen to events... mc.on("swipeleft", function(ev) { $slides.data('superslides').animate('next'); }); mc.on("swiperight", function(ev) { $slides.data('superslides').animate('prev'); }); }
I've found testing on iOS simulator a little flakey, definitely works though. Tested on devices.
Hmmm, using this I get "Uncaught ReferenceError: myElement is not defined."
Is .slider your superslides instance, ala $('.slider').superslides
?
No $('.slider'). is the wrapper.
myElement is the superslides element,follow the logic of these lines below:
myElement = $('.slider').get(0); mc = new Hammer(myElement);
Never was able to get Hammer v2 to work with my setup, but I was able to get TouchSwipe to work:
$('#slides').swipe( {
swipeLeft:function() {
$(this).superslides('animate', 'next');
},
swiperight:function() {
$(this).superslides('animate', 'prev');
}
});
TouchSwipe seems better than Hammer. For example, Hammer is a very flakey when testing in Google's device mode emulator. I've now switched to using TouchSwipe. Cheers
This works perfectly! I corrected som typos :)
$('#slides').swipe( {
swipeLeft:function() {
$(this).superslides('animate', 'next');
},
swipeRight:function() {
$(this).superslides('animate', 'prev');
}
});
Fixed the typo above, thank you!
If you are using Hammer.js with jQuery, you need to include jquery hammer plugin: https://github.com/hammerjs/jquery.hammer.js
Anyone have an example of adding basic touch support (swipeleft/swiperight) using the newest version of Hammer, v2.0.4? I can only get it to work using the version referenced in the touch example, v1.0.5.