私はウェブサイトを構築しています。先頭ページには画像のスライダがあり、テキストが表示されています。画像が最初の画像に戻ったときにテキストのアニメーションが停止する
最初はうまく始まりますが、画像が最初に戻ってきたら、テキストアニメーションは停止します。誰かが私にテキストアニメーションを表示し続けるように助けることができますか?
これは私がやったことです:
var slideIndex = 0;
showSlides();
function showSlides() {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dots");
var container = document.getElementsByClassName("captiontxt");
var tmp = container.innerHTML;
container.innerHTML = tmp;
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex > slides.length) {
slideIndex = 1
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active2", "");
}
slides[slideIndex - 1].style.display = "block";
dots[slideIndex - 1].className += " active2";
setTimeout(showSlides, 6000);
}
.mySlides {
display: none;
}
.fade2 {
-webkit-animation-name: fade;
-webkit-animation-duration: 4.5s;
animation-name: fade;
animation-duration: 4.5s;
}
@keyframes fade {
from {
opacity: .4;
}
to {
opacity: 1;
}
}
@keyframes dropHeader {
0% {
transform: translate(-100%, 0%);
-ms-transform: translate(-100%, 0%);
}
100% {
transform: translate(0%, 0%);
-ms-transform: translate(0%, 0%);
}
}
.captiontxt {
color: #fff!important;
font-size: 25px;
padding: 8px 12px;
position: absolute;
width: 60%;
text-align: center;
left: 0;
bottom: 0;
background-color: #0062f6!important;
opacity: 0.5;
animation-name: dropHeader;
animation-iteration-count: 1;
animation-timing-function: ease-in-out;
animation-duration: 0.6s;
-webkit-animation-name: dropHeader;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease-in-out;
-webkit-animation-duration: 0.6s;
}
<div class="mySlides fade2">
<img src="image put in here" style="width: 100%; height:640px;">
<div class="captiontxt">Write the text here</div>
</div>
(各画像が同じである限り、変更されませんでした)。 "dots"などの不足しているコードを追加して修正してください – mplungjan
'animation-iteration-count:1;'おそらくあなたの犯人です。標準クラスで定義されているため、アニメーション化するときにリセットされることはありません。そのため、実行を永遠に停止します。 – somethinghere