getting touch coordinates from panel with a background image in sencha touch
I am working with a sencha panel in the below fashion. Is there a way to attach a handler say like touch which can return the coordinates of the touch
var world_map = new Ext.Panel({
fullscreen: true,
style: 'background-color:black',
autoScroll:true,
html:'<img id="w_map" src="./images/worldm开发者_JAVA技巧ap.png" width="90%" height="90%"></img>'
});
The basic idea is to be able to detect the points where the user touches, is this possible using such a panel ? thank you
This is definitely possible, and rather easy by using advanced listener options. The trick is to set the element property on the listener so that you are binding tap events to the DOM element over the component.
Here is a working example on Sencha Fiddle: https://fiddle.sencha.com/#fiddle/8ua
var world_map = new Ext.Panel({
fullscreen: true,
style: 'background-color:black',
autoScroll: true,
html: '<img id="w_map" src="./images/worldmap.png" width="90%" height="90%"></img>',
listeners: [{
event: 'tap',
element: 'element',
fn: function(event) {
console.log(event);
alert('Touch Position: ' + event.touch.pageX + ' ' + event.touch.pageY);
}
}]
});
精彩评论