【问题标题】:JavaScript - Video autoplayJavaScript - 视频自动播放
【发布时间】:2019-01-09 11:56:54
【问题描述】:
  <div class="header-container" role="banner">
      <div class="top-image test-top"></div>
      <div id="header-video-container" class="zoom">
         <img id="header-fallback" src="yourimage.jpg" alt="" />
         <video id="header-video" controls loop muted playsinline width="1280" height="720" role="img">
            <source src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4" />
         </video>
      </div>
      <a id="play-pause" class="hover-anim" aria-hidden="true"><i class="fa fa-play" aria-hidden="true"></i></a>
   </div>

   <div class="header-container" role="banner">
      <div class="top-image test-top"></div>
      <div id="header-video-container" class="zoom">
         <img id="header-fallback" src="yourimage.jpg" alt="" />
         <video id="header-video" controls loop muted playsinline width="1280" height="720" role="img">
            <source src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4" />
         </video>
      </div>
      <a id="play-pause" class="hover-anim" aria-hidden="true"><i class="fa fa-play" aria-hidden="true"></i></a>
   </div>

   <div class="header-container" role="banner">
      <div class="top-image test-top"></div>
      <div id="header-video-container" class="zoom">
         <img id="header-fallback" src="yourimage.jpg" alt="" />
         <video id="header-video" controls loop muted playsinline width="1280" height="720" role="img">
            <source src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4" />
         </video>
      </div>
      <a id="play-pause" class="hover-anim" aria-hidden="true"><i class="fa fa-play" aria-hidden="true"></i></a>
   </div>

大家好,我需要创建一个视频部分。主要交互是当每个视频 div 到达视频应该自动播放的屏幕时。我们不需要任何播放/暂停按钮。当它离开屏幕时,它应该会自动暂停。当它再次出现在屏幕上时,视频应该从头开始。我们可以这样做吗?我在这里附上了我的代码。我是java脚本的新手,所以请帮忙。谢谢:)

【问题讨论】:

标签: javascript video


【解决方案1】:

是的,正如其他人的建议,autoplay 属性是您的金票。

【讨论】:

  • 如果我使用的是普通的 html 视频,我们可以删除控件吗?我尝试了很多方法,但没有奏效。你能帮忙吗?
  • 它可以在没有控件的情况下工作&lt;video autoplay controls="false"&gt;&lt;source src="http://example.source/path/to/media.mp4"&gt;&lt;/video&gt;
猜你喜欢
  • 2023-03-05
  • 1970-01-01
  • 1970-01-01
  • 2013-02-13
  • 2021-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多