Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger tap event with jQuery

I need to set tap trigger on some selectors. I'm using jQuery Mobile and this function, so what is not right?

window.onload = load;

function load() {
  $('.togglePlay').trigger('tap');
}
like image 887
Lukas Avatar asked Nov 27 '22 18:11

Lukas


1 Answers

Look into tap and taphold touch event.

// The tap event won't be emitted along with the taphold event
$.event.special.tap.emitTapOnTaphold = false;

$("#fire").on("taphold", function() {
  $(this).addClass("colorize");
});
$("#banana").on("tap", function() {
  $(this).hide();
});
body {
  text-align: center;
}

span {
  font-size: 3rem;
}

span:hover {
  cursor: pointer;
}

.colorize {
  color: transparent;
  text-shadow: 0 0 0 red;
}
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

<h3>If you tap and hold me for 750 milliseconds, I will fill up with color.</h3>
<span id="fire">🔥🔥🔥</span>
<hr />
<h3>If you tap me quick, I will dispear.</h3>
<span id="banana">🍌🍌🍌</span>
like image 100
Penny Liu Avatar answered Dec 05 '22 02:12

Penny Liu