nicinabox / superslides

A fullscreen, hardware accelerated slider for jQuery.
http://archive.nicinabox.com/superslides
MIT License
1.51k stars 443 forks source link

Touch example with Hammer.js v2? #274

Open alwerner opened 9 years ago

alwerner commented 9 years ago

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.

makingthingswork commented 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.

alwerner commented 9 years ago

Hmmm, using this I get "Uncaught ReferenceError: myElement is not defined."

Is .slider your superslides instance, ala $('.slider').superslides?

makingthingswork commented 9 years ago

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);

alwerner commented 9 years ago

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');
    }
});
makingthingswork commented 9 years ago

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

merqurio commented 9 years ago

This works perfectly! I corrected som typos :)

       $('#slides').swipe( {
            swipeLeft:function() {
                $(this).superslides('animate', 'next');
            },
            swipeRight:function() {
                $(this).superslides('animate', 'prev');
            }
        });
alwerner commented 9 years ago

Fixed the typo above, thank you!

marcelo2605 commented 9 years ago

If you are using Hammer.js with jQuery, you need to include jquery hammer plugin: https://github.com/hammerjs/jquery.hammer.js