【问题标题】:Hammer JS not working with backboneHammer JS 不能与骨干一起使用
【发布时间】:2013-04-18 13:11:40
【问题描述】:

我正在尝试让锤子 js 事件与主干一起工作,但无法让它响应事件。 我已经尝试了以下方法..

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

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

我还把下面的代码放在了我的视图中

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

JS 小提琴:http://jsfiddle.net/XcYhD/

代码

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

包含的库——hammer.js、jquery.specialevent.hammer.js 等。

无论如何让它工作?

【问题讨论】:

标签: javascript backbone.js hammer.js


【解决方案1】:

您不需要特殊事件插件,我只需使用 jquery 插件,然后在您的渲染中运行 hammer() 函数。

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

这是一个更新的小提琴:http://jsfiddle.net/XcYhD/20/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多