Touch events in Meteor

*爱你&永不变心* 提交于 2019-12-24 00:57:46

问题


The first thing I started to do with Meteor was start writing a touch-based web application for mobile/tablets. Here's how you reproduce the problem:

First step: create a blank project

meteor create touch_example
cd touch_example
meteor

Second, add these things to the .js file This first bit spits out an alert for touch devices and because they have no console.

Meteor.log = function(input){
    if (typeof console !== 'undefined' && typeof Touch !== "object")
        console.log(input);
    else
        alert(input);
}

And here's the culprit.

Template.touchbox.events = {
    'touchmove' : function (e){
        e.preventDefault();
        Meteor.log('touchy');
    }
};

Last step, change the template around so there's at least one "touchbox" div on the page. IN theory, it should be taking the events. You'll notice that if you change 'touchmove' to 'click' that it works just fine. If you change it to dblclick it will also work fine. Touch events don't do anything.


回答1:


Looks like jQuery as standard doesn't handle these, try using jquery-mobile: http://jquerymobile.com/demos/1.1.0/docs/api/events.html

To add it as a package you might want to look at my other answer here: jQuery-Mobile Meteor sample integration and/or integration guidelines

I found some other help regarding binding touches the same as mouse events however this uses bind and I doubt that will hook up with the live-ui meteor stuff: http://xavi.co/articles/trouble-with-touch-events-jquery




回答2:


This may help. I was looking for a long time to get the click working on mobile for my meteor app. I discovered you can add a comma after your click, and add touchstart

Template.red.events({
'click, touchstart .red': function(event){
            // add function
}


来源:https://stackoverflow.com/questions/10132278/touch-events-in-meteor

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