【发布时间】:2021-05-25 06:36:40
【问题描述】:
所以我设置了 3 个标签,几乎与此类似 - https://www.w3schools.com/howto/howto_js_tabs.asp - 但每个标签下的内容是不同的视频 (HTML)。我的问题是,在更改标签后,前一个标签中的视频/音频会继续播放 - 除非我在切换标签之前暂停视频。对于与此类似的问题,我尝试了几种不同的解决方案,但仍然找不到适用于我的页面的解决方案。
这是我的 HTML -
<!-- Tab links -->
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'BEE')" id="defaultOpen">BEE</button>
<button class="tablinks" onclick="openCity(event, 'CRAB')">CRAB</button>
<button class="tablinks" onclick="openCity(event, 'CROW')">CROW</button>
</div>
<!-- Tab content -->
<div id="BEE" class="tabcontent">
<div class="video">
<video width="852" height="480" controls>
<source src="bee.mov" type="video/mp4">
</video>
</div>
</div>
<div id="CRAB" class="tabcontent">
<div class="video">
<video width="852" height="480" controls>
<source src="crab.mov" type="video/mp4">
</video>
</div>
</div>
<div id="CROW" class="tabcontent">
<div class="video">
<video width="852" height="480" controls>
<source src="crow.mov" type="video/mp4">
</video>
</div>
</div>
以下是我尝试过的一些不同解决方案 - #1 - 我经常回来的主要的 - Pause/stop videos into tabs when I clicked on a tab #2 - How to pause a video when another video's play button is clicked #3 - 我试着看看是否有办法可以将空格键切换到单击此空格键的任意位置 - https://teamtreehouse.com/community/hi-how-can-i-make-the-video-startstop-by-clicking-anywhere-on-the-video-icon-instead-of-targeting-the-play-button
我对 JS 还是很陌生,因此非常感谢任何帮助或建议!谢谢!
【问题讨论】:
-
您需要向我们展示您尝试过的不同解决方案才能获得答案。
标签: javascript html css video