Почему не работает добавление стиля для Dom элемента по setTimeout?
подскажите, пожалуйста, почему не работает setTimeout?
Нужно, чтобы через 2 секунды для Dom элемента добавлялось css свойство.
let testAnim = document.querySelector('.load2');
let testTime = setTimeout(() => {
testAnim.style.display = 'flex';
}, 2000);
.load2 {
display: none !important;
}
.is-typing {
margin-top: 20px;
width: 50px;
justify-content: space-around;
display: flex;
}
.jump1,
.jump2,
.jump3,
.jump4,
.jump5 {
width: 10px;
height: 10px;
border-radius: 100%;
background-color: gray;
}
.jump1 {
animation: typing 1.5s linear infinite;
animation-delay: 01.1s;
}
.jump2 {
animation: typing 1.5s linear infinite;
animation-delay: 01.2s;
}
.jump3 {
animation: typing 1.5s linear infinite;
animation-delay: 01.3s;
}
.jump4 {
animation: typing 1.5s linear infinite;
animation-delay: 01.4s;
}
.jump5 {
animation: typing 1.5s linear infinite;
animation-delay: 1.5s;
}
@keyframes typing {
0% {
transform: translateY(0px);
}
25% {
transform: translateY(0px);
}
35% {
transform: translateY(15px);
}
45% {
transform: translateY(0px);
}
60% {
transform: translateY(-15px);
}
75% {
background-color: white;
transform: translateY(0px);
}
100% {
transform: translateY(0px);
}
}
<div class="test">
<div class="is-typing load2">
<div class="jump1"></div>
<div class="jump2"></div>
<div class="jump3"></div>
<div class="jump4"></div>
<div class="jump5"></div>
</div>
</div>
Ответы (2 шт):
Автор решения: Igor
→ Ссылка
Уберите !important и поменяйте местами
.is-typing {
margin-top: 20px;
width: 50px;
justify-content: space-around;
display: flex;
}
.load2 {
display: none;
}
Автор решения: Igor
→ Ссылка
Просто уберите класс с этим важным наном.
let testAnim = document.querySelector('.load2');
let testTime = setTimeout(() => {
testAnim.classList.remove('load2');
}, 2000);
.load2 {
display: none !important;
}
.is-typing {
margin-top: 20px;
width: 50px;
justify-content: space-around;
display: flex;
}
.jump1,
.jump2,
.jump3,
.jump4,
.jump5 {
width: 10px;
height: 10px;
border-radius: 100%;
background-color: gray;
}
.jump1 {
animation: typing 1.5s linear infinite;
animation-delay: 01.1s;
}
.jump2 {
animation: typing 1.5s linear infinite;
animation-delay: 01.2s;
}
.jump3 {
animation: typing 1.5s linear infinite;
animation-delay: 01.3s;
}
.jump4 {
animation: typing 1.5s linear infinite;
animation-delay: 01.4s;
}
.jump5 {
animation: typing 1.5s linear infinite;
animation-delay: 1.5s;
}
@keyframes typing {
0% {
transform: translateY(0px);
}
25% {
transform: translateY(0px);
}
35% {
transform: translateY(15px);
}
45% {
transform: translateY(0px);
}
60% {
transform: translateY(-15px);
}
75% {
background-color: white;
transform: translateY(0px);
}
100% {
transform: translateY(0px);
}
}
<div class="test">
<div class="is-typing load2">
<div class="jump1"></div>
<div class="jump2"></div>
<div class="jump3"></div>
<div class="jump4"></div>
<div class="jump5"></div>
</div>
</div>