0

Hi I need to trigger a touchmove event manually and pull an element out of the countainer on a mobile device (phonegap, jquery-mobile)

$(elem).bind('touchstart', function(event) {
        event.preventDefault();                  
        var target = event.target;
        target = $(this);

        //this for example just changes the css position obviously
        target.css("margin-top", "50px"); 
});


elem.trigger('touchstart');

Is there a way to setup a event manually and trigger the object with that event like that?

var event = $.Event( "touchstart", { pageX:200, pageY:200 } );

I am using this for drag and drop, the author already mentioned there is no way to do this by interact js and recommended:

- call your drag and drop listeners and give them event objects that you create or - trigger simulated pointer events so that interact sees them as a drag by the user.

any idea?

mboeckle
  • 938
  • 13
  • 29

1 Answers1

0

Can't you declare the function outside the bind() and call it directly?

$(elem).bind('touchstart', handler);
function handler(event) {
    event.preventDefault();                  
    var target = $(event.target);

    //Do stuff with pageX and pageY
    target.css("margin-top", "50px"); 
}

handler({pageX:200, pageY:200, target:elem, preventDefault:function(){}});
user1094553
  • 786
  • 5
  • 15
  • Hi, this has the same effect, maybe I need a combination of touchstart, touchmove?! How can is set the position of target f.e x using touchmove? I need a simultaneously dragging.. – mboeckle Jun 09 '14 at 09:25