Анимация слов на HTML CSS JS
Как сделать на HTML, CSS, JS так, чтобы курсор "|" когда возвращается налево он заменял слово на другое + на новый "цвет"-"background-color"
и потом через 5 секунд снова возвращался направо и изменял всё. Вот как то так:
Эффект должен выглять как на картинке, но вместо картинок долны быть слова:
* {
box-sizing: border-box;
}
body {
padding: 50px;
}
.container {
overflow: hidden;
}
.is-animated {
font-family: 'Helvetica Neue';
font-weight: bold;
padding: 0;
position: relative;
background-color: rgba(255, 146, 246, 0.651);
}
.is-animated span {
display: block;
}
.property {
font-size: 150%;
text-align: right;
border-right: 2px solid #000;
width: 0;
overflow: hidden;
float: left;
-webkit-animation-name: expandProperty;
-webkit-animation-delay: .5s;
-webkit-animation-duration: .8s;
-webkit-animation-fill-mode: forwards;
-webkit-animation-timing-function: ease-in;
}
@-webkit-keyframes expandProperty {
from {
width: 0px;
}
to {
width: 100px;
}
}
<div class="container">
<div class="property is-animated">
<span>text</span>
</div>
</div>
let words = [
"text1",
"text2",
"text3",
"text4",
"text5",
"text6",
"text7"
];
let colors = [
"#0a009d",
"#f91d92",
"#38bc4c",
"#ffce1e",
"#00bbf9 ",
"#9f2dd4",
"#19ddbf",
];
let currentWord = 0;
let intervalid = setInterval(()=>{
if (currentWord == words.length - 1)
currentWord = 0;
else
currentWord++;
let obj = document.getElementById("word");
obj.style.backgroundColor = colors[currentWord];
obj.innerText = words[currentWord];
}, 600);
* {
box-sizing: border-box;
}
body {
padding: 50px;
}
.container {
overflow: hidden;
}
.is-animated {
font-family: 'Helvetica Neue';
font-weight: bold;
padding: 0;
position: relative;
background-color: rgba(255, 146, 246, 0.651);
}
.is-animated span {
display: block;
}
.property {
font-size: 150%;
text-align: right;
border-right: 2px solid #000;
width: 0;
overflow: hidden;
float: left;
-webkit-animation-name: expandProperty;
-webkit-animation-delay: .5s;
-webkit-animation-duration: .8s;
-webkit-animation-fill-mode: forwards;
-webkit-animation-timing-function: ease-in;
animation : expandProperty 10s infinite forwards;
}
@-webkit-keyframes expandProperty {
from {
width: 0px;
}
to {
width: 100px;
}
}
@keyframes expandProperty {
0% {
width: 0px;
}
50% {
width: 100px;
}
100% {
width: 0px;
}}
<div class="container">
<div class="property is-animated">
<span id="word">text</span>
</div>
</div>
Источник: Stack Overflow на русском