Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The behavior of the <code>poster</code> attribute is really driven by the <code>&lt;video&gt;</code> tag itself. You're just telling it, before starting display this image. Like any video element customization, this would require you to have your own elements involved. Basically, you would have:</p> <pre><code>&lt;div class="video-container" style="position:relative"&gt; &lt;video width="x" height="y"&gt;&lt;/video&gt; &lt;img style="position: absolute; top: 0; left: 0; bottom: 0; right: 0"&gt; &lt;/div&gt; </code></pre> <p>You would then have to bind your events, for example with Zepto:</p> <pre><code>$('.video-container img').bind('click', function() { var $img = $(this), $vid = $img.parent().find('video'); $img.animate({opacity: 0}, 1000, 'linear', function() { $img.css({visibility: 'hidden'}); $vid[0].play(); }); }); </code></pre> <p>Similarly, you would listen for the pause event and when it occurs fade back in.</p> <p><em>That said</em>, this is probably a bad idea for two reasons:</p> <ol> <li>This probably won't work for iOS or any device that prevents scripted playback. In these devices, you can only trigger <code>play()</code> when inside a click event handler. Since you're playing a second later, you don't really have control.</li> <li>You're breaking default functionality. When I pause a video, I may want to seek to another moment but I definitely want to know where I left off. The lack of a visual queue takes that away.</li> </ol> <p><strong>Update</strong></p> <p>Here's a different approach that would help you get around the iOS difficulties. In this case, you actually start the video on click, meaning there will be a period of time where the fading image covers the playing video, so it's your call.</p> <pre><code>$('.video-container').each(function() { var $img = $(this).find('img'), $vid = $(this).find('vid'); $img.bind('click', function() { $vid[0].play() }); $vid.bind('play', function() { $img.animate({opacity: 0}, 1000, 'linear', function() { if($vid[0].playing) { $img.css({visibility: 'hidden'}); } }); }); $vid.bind('pause ended', function() { $img.css({visibility: 'visible'}); $img.animate({opacity: 1}, 1000, 'linear'); }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload