带有jQuery和Inview的HTML5视频-如何指向正确的视频元素? [英] html5 video with jquery and inview - how to point to the right video element?

查看:91
本文介绍了带有jQuery和Inview的HTML5视频-如何指向正确的视频元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jquery inview插件查看视图时自动播放视频.由于我无法为视频使用ID,因此我使用html5 <video>作为选择器,所有视频始终开始播放.如何将播放/暂停触发器仅指向当前触发事件的一个元素,而忽略其他所有元素?

I use the jquery inview plugin top automatically play videos when in view. Since I cannot use IDs for the video I use html5 <video> as selector and all videos are always starting to play. How can I point the play/pause trigger only to the one element that is currently triggering the event and ignore all the others?

$('.video-autoplay').on('inview', function(event, isInView) {
  if (isInView) {
    $('video').trigger('play');
  } else {
    $('video').trigger('pause');
  }
});

非常感谢, C

推荐答案

您可以使用this.有关更多信息,请参见此答案.

You can make use of this. For more information, see this answer.

$('.video-autoplay').on('inview', function(event, isInView) {
  if (isInView) {
    $(this).trigger('play');
  } else {
    $(this).trigger('pause');
  }
});

这篇关于带有jQuery和Inview的HTML5视频-如何指向正确的视频元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆