How can I start a video once i'm entering the containing viewport?

79 views
Skip to first unread message

Thomas Handorf

unread,
Nov 27, 2014, 5:46:06 AM11/27/14
to web...@googlegroups.com
How can I start a video once i'm entering the containing viewport?

Thomas Handorf

unread,
Nov 27, 2014, 5:50:54 AM11/27/14
to
assuming you have entered the video using the HTML video tag in the HTML code of the text element:

<video id="passionvideo" width="100%" preload="auto" autoplay="">
<source src="/static/dump/429/Marti.mp4" type="video/mp4">
</video>

The video tag has the id "passion video". You can choose your own id but then you have to replace them also in the code below:

in the hacker shell (ctrl+M) select the JS tab. enter:

$(app).on('view_changed', function(e, view) {
  if (view=='passion') {
    if ($('#passionvideo')[0]) setTimeout(function(){
      console.log('play video');
      $('#passionvideo')[0].currentTime = 0;
      $('#passionvideo')[0].play();
      },500);
  }
});

This will start the video "passion video" when you enter the viewport "passion". If your viewport has a different name, change it in the second line of above code.

Shaun Ramkelawon

unread,
Mar 10, 2016, 11:45:51 AM3/10/16
to Webpgr
How would I make the video pause when leaving the viewport, or stop completely?

Falko

unread,
Mar 10, 2016, 3:25:10 PM3/10/16
to web...@googlegroups.com
You can for example remove the content of the src element


$
(app).on('view_changed', function(e, view) {

 
if (view=='passion') {

   
$('#passionvideo').attr('src', '/static/dump/429/Marti.mp4');
   if ($('#passionvideo')[0]) setTimeout(function(){
      console
.log('play video');
      $
('#passionvideo')[0].currentTime = 0;
      $
('#passionvideo')[0].play();
     
},500);

 
} else {
      $
('#passionvideo').attr('src', '');
 
}
});

Reply all
Reply to author
Forward
0 new messages