Hammer JS not working with backbone

2019-02-17 05:40发布

I'm trying to get hammer js events working with backbone but can't get it to respond to events. I've tried the following already..

http://cijug.net/tech/2013/01/16/backbone-hammer/

https://gist.github.com/kjantzer/4279025

I've also put below piece of code in my view

initialize: function(){
    this.events = _.extend({}, this.defaultEvents, this.events||{});      
}

JS Fiddle : http://jsfiddle.net/XcYhD/

Code

<div id="swiping"></div>

JS

AppView = Backbone.View.extend({

  el: '#swiping',          

  events: {
    'swipe': 'swipeMe'
  },

  render: function(){             
    this.$el.html('<h2>Swipe Me</h2>');
  },

  swipeMe: function(e){                
    alert('swiped ' + e.direction);
  }

});

var view = new AppView();
view.render(); 

Libraries Included - hammer.js , jquery.specialevent.hammer.js , etc..

Anyway to get it working ?

1条回答
唯我独甜
2楼-- · 2019-02-17 05:51

You don't need the special events plugin, I'd just go with the jquery plugin and then run the hammer() function in your render.

  render: function(){             
    this.$el.html('<h2>Swipe Me</h2>');
    this.$el.hammer();
  },

Here's an updated fiddle: http://jsfiddle.net/XcYhD/20/

查看更多
登录 后发表回答