首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Javascript和CSS动画超时

Javascript和CSS动画超时
EN

Stack Overflow用户
提问于 2022-09-07 18:16:26
回答 1查看 29关注 0票数 1

我最近有点麻烦。我在数组中有5行文本,随着计时器的变化而变化,但我认为有些地方css计时器动画的时间不是正确的,或者我设置@keyframes幻灯片的方式没有正确设置。

文本透明度下降到0以后,文本之间的变化时间也很长。

它应该做的是:显示文本

代码语言:javascript
复制
let textElement = document.querySelector("p")


let textArray = [
  "Are you looking for a quick learner?",
  "Someone who is ever evolving?",
  "Someone who strives to improve their knowledge?",
  "Someone who loves problem-solving and finding solutions?",
  "Someone who has the tenacity to succeed?"
]
let index = 0;
textElement.innerText = textArray[index]

setInterval(() => {
  index = (index + 1) % textArray.length
  textElement.innerText = textArray[index]

}, 5000)
代码语言:javascript
复制
.background {
  background: var(--light--colour);
  height: 88.4vh;
}

@keyframes animateBack {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

p {
  height: 2em;
  position: absolute;
  font-size: 32px;
  color: var(--darkest--colour);
  margin-left: 1em;
  width: 12em;
  margin-top: 0em;
  animation: slidesdown 5s ease infinite;
}

.vert-line {
  border-left: 2px solid #012326;
  margin-top: -17em;
  height: 7em;
  margin-left: 10em;
}

@keyframes slidesdown {
  0%,
  50% {
    transform: translate(0, 0em);
    opacity: 1;
  }
  50%,
  100% {
    -webkit-transform: translate(0, 1em);
    opacity: 0;
  }
}
代码语言:javascript
复制
<main>
  <div class="background"></div>

  <div class="vert-line">
    <p></p>
  </div>
</main>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-07 19:20:21

代码语言:javascript
复制
let textElement = document.querySelector("p")


let textArray = [
  "Are you looking for a quick learner?",
  "Someone who is ever evolving?",
  "Someone who strives to improve their knowledge?",
  "Someone who loves problem-solving and finding solutions?",
  "Someone who has the tenacity to succeed?"
]
let index = 0;
textElement.innerText = textArray[index]

setInterval(() => {
  index = (index + 1) % textArray.length
  textElement.innerText = textArray[index]

}, 5000)
代码语言:javascript
复制
.background {
  background: var(--light--colour);
  height: 88.4vh;

}

@keyframes animateBack {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

p {
  height: 2em;
  position: absolute;
  font-size: 32px;
  color: var(--darkest--colour);
  margin-left: 1em;
  width: 12em;
  margin-top: 0em;
  animation: slidesdown 5s ease infinite;
}

.vert-line {
  border-left: 2px solid #012326;
  margin-top: -17em;
  height: 7em;
  margin-left: 10em;
  
}

@keyframes slidesdown {
  0%,
  50% {
    transform: translate(0, 0em);
    opacity: 1;
  }
  
  100% {
    -webkit-transform: translate(0, 1em);
    opacity: 0;
  }
}
代码语言:javascript
复制
<main>
  <div class="background"></div>

  <div class="vert-line">
    <p></p>
  </div>
</main>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73639969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档