5

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');
}
Omar
  • 32,302
  • 9
  • 69
  • 112
Lukas
  • 7,384
  • 20
  • 72
  • 127

5 Answers5

1

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>
Penny Liu
  • 15,447
  • 5
  • 79
  • 98
  • 1
    For Your second sentence, You may need to set `$.event.special.tap.emitTapOnTaphold` to `false`. See here:https://api.jquerymobile.com/taphold/ – deblocker Mar 11 '20 at 17:44
0

try:

$(document).ready(function(){
    $('.togglePlay').trigger('click');
});
suhailvs
  • 20,182
  • 14
  • 100
  • 98
-1

Assuming the loading page has a div containing data-role=page and its id is mypage, you could use the pageinit event to fire up the click on '.togglePlay' like this :

$(document).on("pageinit", "#mypage", function () {
  $('.togglePlay').trigger('click');
});

References

Community
  • 1
  • 1
krishwader
  • 11,341
  • 1
  • 34
  • 51
-1

I use jQuery tap() method.

$('.togglePlay').tap();

http://api.jquerymobile.com/tap/

This works for me :)

Suryavel TR
  • 3,576
  • 1
  • 22
  • 25
-2

you should be able to set autoplay=true or some other setting with...

<video controls autoplay>
    <source src="movie.mp4" type="video/mp4">
    <source src="movie.ogg" type="video/ogg">
    Your browser does not support the video tag.
</video> 

example from: http://www.w3schools.com/tags/att_video_autoplay.asp

without the use of js