7

I use a carousel in Sencha Touch 2. How I can handle swipe-left and swipe-right events ?

Dragan Menoski
  • 1,092
  • 14
  • 33

1 Answers1

12

One way is to listen to the swipe event on your carousel items along with using Ext.event.Event.direction to handle the direction of your swipe:

listeners: {
    initialize: function(c) {
        this.element.on({
            swipe: function(e, node, options) {
                if(e.direction == "left") {
                    alert("Hey! I swipe left");
                } else {
                    alert("Hey! I swipe right");
                }
            }
        });
    }
} 

Working Demo: http://www.senchafiddle.com/#TLBZB

Eli
  • 14,779
  • 5
  • 59
  • 77
  • But it works sometimes only. Sometimes this swipe function is not rendering in my case... – SSS May 28 '13 at 11:06
  • 1
    It should be `else if (e.direction == "right")` instead of a simple `else {...}`. Otherwise that block will be triggered whenever you swipe to the top, bottom and the right – DuKes0mE Nov 30 '14 at 18:36