ObiettivoCome sostituire clic con TouchStart su dispositivi iOS
Per chiudere il div genitore di un tag di ancoraggio quando si fa clic. Nel seguente codice, voglio nascondere div performance_tt quando l'utente fa clic sul tag di ancoraggio close_performance_tt.
Problema
Incapace di farlo funzionare su dispositivi iOS dopo aver trascorso diverse ore a questo. Funziona bene su tutto il resto, anche un dispositivo BlackBerry 10.
<div id="performance_tt" style="display: none;width: 300px;height: 200;overflow: auto;padding: 5px;background-color: yellow;">
<div>Website performance has become an important consideration for most sites.
The speed of a website affects usage and user satisfaction, as well as search engine rankings, a factor that directly correlates to revenue and retention.
As a result, creating a system that is optimized for fast responses and low latency is key.</div>
<a id="close_performance_tt" href="#">Close</a>
<script>
var userAgent = navigator.userAgent.toLowerCase();
var isiOS = (navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false);
if (isiOS) {
$("#close_performance_tt").bind('touchstart', function() {
alert('Touch-start event triggered');
});
} else {
$("#close_performance_tt").bind('click', function() {
alert('Click event triggered');
});
}
</script>
</div>
perché non utilizzare '$ ("# close_performance_tt"). Bind ('click TouchStart', ..)' al posto del 'if..else' –
Ma non è la causa del problema, giusto? – KalC
devi assicurarti che il flag 'isiOS' abbia il valore giusto –