Hammer JS not working with backbone

戏子无情 提交于 2019-12-01 02:16:31

问题


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:


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/



来源:https://stackoverflow.com/questions/16083933/hammer-js-not-working-with-backbone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!