I wonder how to add text marquee dynamically, I have tried to using marquee tags like this :
<marquee scrollamount="5" loop="infinite" id="paragraph"> This is sample of my marquee </marquee>
and I append text like this :
document.getElementById("paragraph").innerHTML += ' This is how I to append text';
It's working but the problem is when I append text to marquee the first animation not working properly (text from right to left not finish and start looping again), so marquee only running until text before it's append and loop and when animation start loop, then the marquee animation runs all text (text from right to left finish until its finish and disappear then loop again)
And I have also tried make marquee using keyframes like this:
function AppendData(){
document.getElementById("marquee").innerHTML += 'This is how i append data to marquee';
}
@keyframes marquee {
0% { text-indent: 100% }
100% { text-indent: -100% }
}
@-webkit-keyframes marquee {
0% { text-indent: 100% }
100% { text-indent: -100% }
}
.marquee {
overflow: hidden;
white-space: nowrap;
animation: marquee 17s linear infinite;
-webkit-animation: marquee 17s linear infinite;
}
.marquee:hover {
-webkit-animation-play-state: paused;
animation-play-state: paused;
}
<button onclick="AppendData()">Append Data</button>
<p class="marquee" id="marquee">This is my marquee not using marquee tags but using the keyfames by css.</p>
but the problem is same with using marquee tags, because 100% { text-indent: -100% }
not dynamic.
My question is how to make marquee runs dynamically until finish or disappear from left to right when I append text in the first running marquee?