I am experimenting with CSS3 animations to create a marquee effect and want to trigger a function when the animation changes from running to paused or initial state.
HTML:
<div class='animationBackground'><p id="marqueeText">Scrolling Text Goes Here</p></div>
<div id="animationState">Animation State</div>
<button id='stop' type"button" onclick=stopInterval()>Stop Logging</button>
CSS:
@keyframes marquee
{
0% { transform: translate(0%, 0); }
100% { transform: translate(-200%, 0);}
}
p {
margin-left: 100%;
padding-inline-end: 50px;
display: inline-block;
white-space: nowrap;
color: #ffffff;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 30pt;
z-index: 10;
animation: marquee 25s linear 0s 1
}
.animation{
width: 100%;
background-color: darkblue;
vertical-align: bottom;
}
JavaScript:
var myVar = setInterval(myTimer, 5000);
function myTimer() {
var marqueeText = document.getElementById('marqueeText');
var animationState = document.getElementById('animationState');
animationState.innerHTML = marqueeText.style.animationPlayState;
console.log(marqueeText.style.animationPlayState);
if(marqueeText.style.animationPlayState == "running"){
doSomething();
}
}
function stopInterval(){
clearInterval(myVar);
}
The following code does not display any output:
animationState.innerHTML = animatedText.style.animationPlayState;
Similarly, this code results in a blank <div>
and no output in the console:
console.log(animatedText.style.animationPlayState);
Is it feasible to obtain and manipulate states like running|paused|initial|inherit
using Javascript through the doSomething() function?