0

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

many thanks, C

Carsten H
  • 727
  • 10
  • 26

1 Answers1

0

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');
  }
});
IronAces
  • 1,695
  • 1
  • 24
  • 31
GodD
  • 16
  • thanks, that brought me to the right idea. :-) "This" works with a small edit. The first selector $('.video-autoplay') needs to contain the video element like $('.video-autoplay video') since the video element needs to be triggered. – Carsten H Aug 25 '17 at 10:45