is there a callback in builder to get touch position rather than adding some codes in the source?
is there a callback in builder to get touch position rather than adding some codes in the source?
Hi Shuang,
You can read about available events here: http://api.jquerymobile.com/category/...
Most often, the click/touch coordinates are inside the event object that is passed as an event handler argument.
Hello!
Can you tell, how to retrieve those x,y coords? I could not find out it with docs above...
Thanks!
Great, it works!
But... My alert appears on other screens also. It seems, I have to disable that callback, right?
And another question - how can I assign tap handler to specific element (image)? I tried like this, but did not work:
$( "#lblTourID" ).bind( "tap", function tapHandler(event){
alert('x : ' + event.pageX + ' , y : ' + event.pageY);
});
lblTourID - is Name of element, assigned in UI builder
This code works, but on next screens also:
$( document ).bind( "tap", function tapHandler(event){
alert('x : ' + event.pageX + '\ny : ' + event.pageY);
});
Oh-h-h...... I ' ve just found out that I can call JS on Tap event on image (and outer elements) in UI builder. How can I get tap coordinates? There is no parameter, like in handler function.
A-m-m.... I have found the solution for getting the location of an image click.
here is the code:
$('[dsid="Image1"]').bind('tap', function(e){
var x = e.pageX;
var y = e.pageY;
alert([x, y]);
})
Please, let me know, if this is good solution.
Thank you very much for your help and sorry for bothering...
There is easier way.
Add Run JavaScript action on Tap event on image component. Use this js code
precodevar e = arguments[0];
var x = e.pageX;
var y = e.pageY;
alert([x, y]);
/code/pre
WOW, cool !
Thank you, Oleg!
How can I get relative position in Tap event?
Code: Select all
I use this code on Load Event and it works:
// SET TOUCH EVENT (relatively to parent, not on screen)
$('[dsid="iii"]').bind('tap', function(e){
var posX = $(this).position().left,
posY = $(this).position().top;
alert((e.pageX - posX) + ' , ' + (e.pageY - posY));
})
But on Tap Event I got Nan. I think "this" is not correct object.
When I change this to document I got exception:
Uncaught TypeError: Cannot read property 'top' of undefined
var posX = $(document).position().left,
posY = $(document).position().top;