Mobile gestures in backbone.js

Can I have mobile gestures like swipe, tap, pinch, etc. in the events of "Backbone.js View"? To be more specific, this is my code.

Backbone.View.extend({ initialize:function(){ //initialization }, Events:{ "swipe-left #homeBtn":"homeSwipe" }, homeSwipe:function(){ alert("Event Swipe left triggered!"); } }); 

Can I use mobile gestures, for example, swipe, swipe left / right, pinch, tap, etc. to work with backbone.js?

+6
source share
2 answers

Backbone relies on jQuery.bind to manage DOM events.

So the question is, if jQuery supports these events and looks like jQuery Mobile does , now you should check how to integrate jQuery Mobile and Backbone .

0
source

Download and enable Hammer.js , and then use events with basic views, as usual!

 events:{ 'swipe': 'onSwipe' }, initialize: function(){ // I think you can get away doing this here once, but I have not tested. // If not, just move it to the `render` method new Hammer(this.el); }, onSwipe: function(e){ console.log(e.direction); // left or right } 

Alternatively, you can take a look at my simple Backbone view Gist.

Update

Based on the feedback, it seems like new Hammer(this.el) needs to be called in spine mode for this to work. I updated this example to reflect this.

+8
source

Source: https://habr.com/ru/post/913807/


All Articles