multiple touches: touchend event fired only when a touchmove occurs

后端 未结 4 2074
忘掉有多难
忘掉有多难 2021-02-19 23:38

I would like to add some multitouch features to my javascript application when it is accessed from an ios device (and maybe android later).

I want to provide a shift

4条回答
  •  甜味超标
    2021-02-20 00:21

    Ok, I have implemented this solution and it seems to work.

    //Initialize the tap touch
    function ManageTapTouch() {
        this.__enabled__ = false;
    }
    
    ManageTapTouch.prototype.init = function(){
        $("#hold").bind('touchstart', $.proxy(this.__enable__, this));
        $('#hold').bind('touchend', $.proxy(this.__disable__, this));
        $('#tap').bind('touchstart',  $.proxy(this.__changeColorOnHold__, this));
        $('#tap').bind('touchend',  $.proxy(this.__changeColorOnOut__, this));
    };
    ManageTapTouch.prototype.__enable__ = function(event) {
        this.__enabled__ = true;
    };
    ManageTapTouch.prototype.__disable__ = function(event) {
        this.__enabled__ = false;
        $('body').css('background-color', 'blue'); 
    };
    ManageTapTouch.prototype.__changeColorOnHold__ = function(event) {
        if (this.__enabled__){
            $('body').css('background-color', 'black');
        }
    };
    ManageTapTouch.prototype.__changeColorOnOut__ = function(event) {
        $('body').css('background-color', 'blue');
    };
    
    new ManageTapTouch().init();
    

    You can see it running here: http://jsfiddle.net/Tb6t6/15/

    Also you can try another way on the iPhone using multitouch with: event.originalEvent.touches[0].pageX and event.originalEvent.touches[0].pageY where the index is the finger on the screen and event is the event fired on TouchStart. With this topics you can implement your own version of this action or use the one I propose here.

提交回复
热议问题