使用javaScript添加字幕

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用javaScript添加字幕相关的知识,希望对你有一定的参考价值。

How can I print the data in the array one by one into the scrolling text using javascript.
How can I print the data in the array one by one into the scrolling text using javascript.
How can I print the data in the array one by one into the scrolling text using javascript.
How can I print the data in the array one by one into the scrolling text using javascript.

var arrayList=[
	["Ambitioni dedisse scripsisse iudicaretur."],
	["Ambitioni dedisse scripsisse iudicaretur."],
	["Ambitioni dedisse scripsisse iudicaretur."],
	["Ambitioni dedisse scripsisse iudicaretur."],
	["Ambitioni dedisse scripsisse iudicaretur."],
	["Ambitioni dedisse scripsisse iudicaretur."],
	["Ambitioni dedisse scripsisse iudicaretur."]
];
  .quetoBody{
      width: 300px; 
      margin-left: 150px; 
      margin-top: 40px; 
      background-color: aqua; 
      padding: 15px;
  }
  @keyframes slydeAnimation {
    0%   { text-indent: 430px }
    100% { text-indent: -485px }
  }

  @-webkit-keyframes slydeAnimation {
    0%   { text-indent: 430px }
    100% { text-indent: -485px }
  }

  .slyde {
    overflow: hidden;
    white-space: nowrap;
    animation: slydeAnimation 17s linear infinite;
    -webkit-animation: slydeAnimation 17s linear infinite;
  }

  .slyde:hover {
    -webkit-animation-play-state: paused;
    animation-play-state: paused;
  }
<html>
<head></head>
<body>
 <div class="quetoBody">
   <p id="queto" class="slyde">
    Ambitioni dedisse scripsisse iudicaretur.
  </p>
 </div>
</body>
</html>
How can I print the data in the array one by one into the scrolling text using javascript.
How can I print the data in the array one by one into the scrolling text using javascript.
How can I print the data in the array one by one into the scrolling text using javascript.
How can I print the data in the array one by one into the scrolling text using javascript.
答案

只需更改您需要的时间,您就可以开始了

function run() {
    setInterval(() => {
        document.querySelector("p").textContent = arrayList[count];
        if (count + 1 == arrayList.length) {
            count = 0;
        } else {
            count++;
        }
    }, 5000);
}

var count = 0;

var arrayList = [
   ["Ambitioni dedisse scripsisse iudicaretur. 1"],
   ["Ambitioni dedisse scripsisse iudicaretur. 2"],
   ["Ambitioni dedisse scripsisse iudicaretur. 3"],
   ["Ambitioni dedisse scripsisse iudicaretur. 4"],
   ["Ambitioni dedisse scripsisse iudicaretur. 5"],
   ["Ambitioni dedisse scripsisse iudicaretur. 6"],
   ["Ambitioni dedisse scripsisse iudicaretur. 7"]
];
  .quetoBody{
      width: 300px; 
      margin-left: 150px; 
      margin-top: 40px; 
      background-color: aqua; 
      padding: 15px;
  }
  @keyframes slydeAnimation {
    0%   { text-indent: 430px }
    100% { text-indent: -485px }
  }

  @-webkit-keyframes slydeAnimation {
    0%   { text-indent: 430px }
    100% { text-indent: -485px }
  }

  .slyde {
    overflow: hidden;
    white-space: nowrap;
    animation: slydeAnimation 5s linear infinite;
    -webkit-animation: slydeAnimation 5s linear infinite;
  }

  .slyde:hover {
    -webkit-animation-play-state: paused;
    animation-play-state: paused;
  }
<html>
<head></head>
<body onload=run()>
 <div class="quetoBody">
   <p id="queto" class="slyde">
    
  </p>
 </div>
</body>
</html>

以上是关于使用javaScript添加字幕的主要内容,如果未能解决你的问题,请参考以下文章

常用Javascript代码片段集锦

JavaScript网页特效5则

[新增ST-001片段]全程字幕-20套UML+Enterprise Architect建模示范视频

覆盖javascript以消除闪烁

[新增EA003考勤系统演示片段]全程字幕-22套UML+Enterprise Architect建模示范视频

使用javascript将字幕与电影同步