最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to trigger tap event with jQuery - Stack Overflow

programmeradmin2浏览0评论

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');
}

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');
}
Share Improve this question edited Jun 24, 2013 at 9:16 Omar 31.7k9 gold badges72 silver badges116 bronze badges asked Jun 24, 2013 at 7:58 LukasLukas 7,74420 gold badges79 silver badges127 bronze badges 10
  • Maybe you should use $.ready function instead of window's onload event – Pavel Gruba Commented Jun 24, 2013 at 8:03
  • $(document).ready(function(){ – suhailvs Commented Jun 24, 2013 at 8:04
  • What do you want to achieve exactly? – Omar Commented Jun 24, 2013 at 9:15
  • i need to automaticly fireup some video on ipad... so i'm trying to simulate pla ybutton click – Lukas Commented Jun 24, 2013 at 9:20
  • 1 @user10089632 sory man but i don't remember this case, this was at 2013 :) also haven't used jQuery since more then year now – Lukas Commented Aug 22, 2017 at 23:27
 |  Show 5 more ments

5 Answers 5

Reset to default 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./mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery./jquery-1.11.1.min.js"></script>
<script src="http://code.jquery./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">
发布评论

评论列表(0)

  1. 暂无评论