I want to make a typography animation where I want to animate the second text which is colored and also it has multiple text to animate. In this animation, I want to show and hide the text one after the other with a cursor-moving effect. But in this, I have an issue to make the background transparent, because in the background I want to run the video also, so it is compulsory to make the span’s background transparent so that it looks permanently hidden
const text = document.querySelector(".sec-text");
const textLoad = () => {
setTimeout(() => {
text.textContent = "Real Estate";
}, 0);
setTimeout(() => {
text.textContent = "The Best Deal";
}, 4000);
}
textLoad();
setInterval(textLoad, 8000);
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;500;600&display=swap');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body{
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #010718;
overflow: hidden;
}
.container{
width: 360px;
overflow: hidden;
}
.container .text{
position: relative;
color: #c32000;
font-size: 30px;
font-weight: 600;
}
.container .text.first-text{
color: #FFF;
}
.text.sec-text:before{
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: #010718;
border-left: 2px solid #c32000;
animation: animate 4s steps(8) infinite;
}
@keyframes animate{
40%, 60%{
left: calc(100% + 4px);
}
100%{
left: 0%;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="textAnim.css">
<title>Document</title>
</head>
<body>
<div class="container">
<span class="text first-text">Absolute</span>
<span class="text sec-text"></span>
</div>
</body>
</html>
.
2
Answers
This is what I managed to do. The idea is to vary the width of the box containing the red text. So there’s nothing to cover up because the text will be hidden when it overflows the width of the box.
It’s not perfect because the two red texts don’t have the same length and the animation ignores that, but I think it still looks pretty good.
You could just animate the text itself: