jquery .play无法在移动设备上运行

我的页面上有许多HTML5 元素,并且所有元素都在桌面上运行良好。 但是,在iOS Safari上,只有长时间保持video播放,而不是正常点击(应该复制’click’jqueryfunction)。 任何人都可以建议为什么video没有播放? 为什么它会在短暂的持有后这么做?

 $(document).ready(function() { // Preload the video setTimeout(function() { $('.video video')[0].load(); }, 0); $('.video video').click(function() { if ($(this).hasClass('is-playing')) { $(this).removeClass().addClass('is-paused'); // Pause video $(this)[0].pause(); } else { $(this).removeClass().addClass('is-playing'); // Play video $(this)[0].play(); } return false; }); }); 
   

您需要在on function on使用touchstart事件:

 $(document).ready(function() { setTimeout(function() { $('.video video')[0].load(); }, 0); $('.video video').on('click touchstart', function() { // Change is here -------^ if ($(this).hasClass('is-playing')) { $(this).removeClass().addClass('is-paused'); $(this)[0].pause(); } else { $(this).removeClass().addClass('is-playing'); $(this)[0].play(); } return false; }); }); 

touchstart