2013-02-12 13 views
6

Qualcuno può dirmi perché l'evento touchenter non funziona in questo codice. Il mouseenter funziona bene su un desktop. Dovrebbe essere così semplice, mi manca qualcosa però.evento touchenter non chiamato

Esempio qui - http://jsfiddle.net/gCEqH/6/

codice completo qui sotto:

<!DOCTYPE html> 
<html> 
    <head> 
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
    </head> 

    <body> 
     <img id="myImg" src="http://jackiehutchings.com/wp-content/uploads/2011/09/g-plus-icon-96x96.png" />   

     <script> 
      $(window).load(function() { 
      $('#myImg').on("touchenter mouseenter", function(event){ 
       alert('entered!'); 
      }); 
     }); 
     </script> 
    </body> 
</html> 
+0

Sei sicuro, funziona per me su Windows Phone? Quale browser? – enginefree

+0

Non funziona su telefono Android o iPad. Al telefono ho provato sia il browser standard che Opera. – Justin

+0

funziona bene per me in ipad. funziona bene quando ci si sta sopra. stai cercando hover in touch? – karthik

risposta

0

Forse qualcosa di simile avrebbe funzionato?

var elementIdTouching = ""; 
$('body').on("touchmove", function(e){ 
    var tList = e.touches; // get list of all touches 
    for (var i = 0; i < tList.length; i++) { 
     var thisTouch = tList[i]; // not 100% sure about this 
     var elementTouching = document.elementFromPoint( 
      thisTouch.screenX, 
      thisTouch.screenY 
     ); 
     if (elementTouching.id != elementIdTouching) { 
      elementIdTouching = elementTouching.id; 
      if (elementTouching.id == "myImg") { 
       alert("entered!"); 
      } 
     } 
    } 
}).on("touchend", function(e){ 
    elementIdTouching = ""; 
}); 
$('#myImg').on("mouseenter", function(e){ 
    alert('entered!'); 
}); 

tlist ~ https://developer.mozilla.org/en-US/docs/Web/API/TouchList

Disclaimer: non ho ancora testato questo.

+0

Questo approccio funziona ma è molto lento. Però ho trovato una soluzione. (vedi i miei commenti sopra). – Justin

+0

In base a quirksmode, 'clientX' e' clientY' sarebbero una scelta migliore di 'screenX' e' screenY': http://www.quirksmode.org/dom/w3c_cssom.html#t20 – Webthusiast

Problemi correlati