J'ai une télécommande comme curseur (matériel).Comment soumettre un clic via l'orientation x et y?
Matériel externe via SDK à Javascript je reçois un curseur. Où j'obtiens x, x, y, y position et cliquez sur commande.
Mais, Comment soumettre cliquez sur cette position? (peu importe ce que l'élément est là cette position, je dois soumettre le clic sur cette position)
if (_label == rs.cursor.GestureType.CURSOR_CLICK) {
// I have: x, x, y, y
/*
Following method works:
but i have too many buttons, how to apply dynamic click without tracking which element?
var myButton = document.getElementById("mediaplayer");
var rect = myButton.getBoundingClientRect();
if (x >= rect.left &&
x <= rect.right &&
y >= rect.top &&
y <= rect.bottom){
myButton.click();
}
*/
}
EDIT:
//
// 1 - Find Active DIV/MAP/Container?
//
var layerID = $('#layoutmain').attr('usemap');
if (_label == rs.cursor.GestureType.CURSOR_CLICK) {
//
// 2 - Loop each buttons of that container
//
$('#' + layerID).find('area').each(function(){
var onclick_function = $(this).attr('onclick') ;
var coords = $(this).attr('coords');
coords = coords.split(' ').join('');
var coords_array = coords.split(',');
console.log('>>> we have: ',
onclick_function ,
coords,
coords_array);
var rectleft = coords_array[0];
var recttop = coords_array[1];
var rectright = coords_array[2];
var rectbottom = coords_array[3];
//
// 3 - Match the RANGE of buttons with the coordinates
//
if (x >= rectleft && y >= recttop &&
x <= rectright && y <= rectbottom){
$(this).trigger('click');
}
});
}
Pourquoi devez-vous créer un bouton? Ne pouvez-vous pas déclencher un événement de soumission? –
Et vous pouvez utiliser jQuery, non? –
Copie possible de [Déclenchement d'un clic JavaScript() sur des coordonnées spécifiques] (http://stackoverflow.com/questions/2845178/triggering-a-javascript-click-event-at-specific-coordinates) – Andrey