【问题标题】:Randomly changing video with JS - javascript用JS随机改变视频 - javascript
【发布时间】:2021-11-28 11:12:25
【问题描述】:

我是新手,我想在加载网站时显示随机视频,我找到了这段代码,更改了一些东西并实现了我想要的,但现在我需要每个视频都有一个小描述和我附上的链接这个图片我想要类似的东西,这里有人可以帮助我吗,提前谢谢。

https://piic.me/img-134

<video autoplay muted loop id="OracleVid" style="display: auto; max-width:100%;">
  <source id="OracleVidSRC"/>
</video>

<script>
var clip = document.querySelector("#OracleVidSRC");
var video = document.querySelector("#OracleVid");
var oracleVidArray = [
  "http://localhost/website/wp-content/uploads/2021/10/logitech1_xlarge_preview.mp4",
  "http://localhost/website/wp-content/uploads/2021/10/6b_xlarge_preview.mp4",
  "http://localhost/website/wp-content/uploads/2021/10/elementor1_xlarge_preview.mp4"
];


window.onload = function oracleFunction() {
  clip.src = oracleVidArray[Math.floor(Math.random() * oracleVidArray.length)];;
  //video.style = "display: block";
  video.load();
}

</script>

您还可以在此处查看原始代码: Randomly changing video src with JS

我只是想在上面的js代码中包含这个,(每个视频都有不同的url和描述)

<figure class="wp-block-video">
     <a rel="noreferrer noopener" href="https://website.com" target="_blank">
          <video autoplay="" loop="" muted="" src="http://localhost/website/wp-content/uploads/2021/10/logitech1_xlarge_preview.mp4" playsinline="">
          </video>
     </a>
     <figcaption><strong><code><span style="color:#111111" class="has-inline-color">Description 
          </span></code></strong><a rel="noreferrer noopener" href="https://website.com" target="_blank">website.com</a></figcaption>
</figure>

【问题讨论】:

    标签: javascript html random html5-video


    【解决方案1】:

    在以下位置添加类“none”:

    <figure class="wp-block-video none">
    

    编辑css类:

    .none { display:none; }
    

    在带有“

    <video autoplay muted loop id="OracleVid" style="display: auto; max-width:100%;">
      <source id="OracleVidSRC"/>
    </video>
    
    <figure class="wp-block-video none">
     <a rel="noreferrer noopener" href="https://website.com" target="_blank">
          <video autoplay="" loop="" muted="" src="http://localhost/website/wp-content/uploads/2021/10/logitech1_xlarge_preview.mp4" playsinline="">
          </video>
     </a>
     <figcaption><strong><code><span style="color:#111111" class="has-inline-color">Description 
          </span></code></strong><a rel="noreferrer noopener" href="https://website.com" target="_blank">website.com</a>
    

    并且在函数 oracleFunction() 中删除类无。

    【讨论】:

    • 感谢兄弟的帮助,我已经在js中包含了这段代码,但是没有用。
    猜你喜欢
    • 1970-01-01
    • 2016-07-27
    • 1970-01-01
    • 2019-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-04
    • 1970-01-01
    相关资源
    最近更新 更多