我在使用backbone.js和hammer.js实现触摸事件时遇到了问题
我试着用传统的方式实现触摸,即在" events“section.But中定义触摸事件,这对我不起作用。
请找到我下面的代码
define(['Backbone','underscore','Handlebars','Hammer'],function(Backbone,_,Handlebars,Hammer) {
//getting the type of device in a variable using "userAgent"
window.MOBILE = navigator.userAgent.match(/mobile/i);
var HeadderView = Backbone.View.extend(
{
el: 'body',
touchPrevents : false,
initialize: function()
{
this.el$ = $(this.el);
},
events: function() {//returning different functions based on the device
return MOBILE ?
{
'tap #headcontent': 'handleTap',
} :
{
'click #headcontent':'clickbackbone',
}
},
//declaring the corresponding functions
handleTap: function(){
alert("tap event");
},
clickbackbone:function(){
alert('backbone click');
},
render: function ()
{
//rendering the template and appending it to the page
var that = this;
require(['text!gaming/gameHeadder/headder.html'],function(HeaderTemplate){
var template = Handlebars.compile(HeaderTemplate);
var context = {title: "Tick Tack Toe", imageURL: "images/logo.jpg"}
var htmlTemplate = template(context);
that.el$.html( htmlTemplate);
});
},
});
return new HeadderView();
}
);有人能帮我改正我的代码吗
发布于 2015-04-09 02:21:23
这不是Hammer的工作方式。Backbone对HammerJS一无所知。
如果你真的想在Hammer中使用Backbone风格的事件委派,你可能会想看看backbone.hammer项目。
https://stackoverflow.com/questions/23488850
复制相似问题