Hammer JS 不适用于主干 [英] Hammer JS not working with backbone

查看:21
本文介绍了Hammer JS 不适用于主干的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.ne​​t/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 小提琴: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 等.

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

无论如何让它工作?

推荐答案

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

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

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

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

这篇关于Hammer JS 不适用于主干的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆