Having an issue with the "Start button" that plays both animation and background sounds. When I pause it, the animation does not stop where it left off and starts from the beginning again.
I tried using animation-play-state: pause
and animation-fill-mode: forwards
but I must be doing something wrong because it's not working as expected.
function startAnimation(){
var audio = document.getElementById("audio");
audio.play();
document.getElementById('target').className ='animated';
}
function pauseAnimation(){
var audio = document.getElementById("audio");
audio.pause();
document.getElementById('target').className ='noo';
}
button {
background-color: darkgreen;
border-radius: 50px;
border: none;
color: white;
padding: 13px 50px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
box-shadow: 0 3px 3px 0 rgba(0,0,0,0.4), 0 2px 1px rgba(0,0,0,0.1);
}
button:hover{
background-color: green;
border-radius: 50px;
border: none;
color: white;
padding: 13px 50px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
box-shadow: 0 6px 6px 0 rgba(0,0,0,0.25),
0 0 4px 2px rgba(0,0,0,0.05);
transform: translateY(-2px);
}
p {
position: relative;
display: inline-block;
font-size: 18px;
font-weight: 80;
color: black;
overflow: hidden;
background: linear-gradient(to right, darkgreen, darkgreen 50%, black 50%);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-size: 200% 100%;
background-position: 100%;
}
.animated {
transition: background-position 9000ms linear;
background-position: 0 100%;
animation-fill-mode: forwards;
}
.noo > {
-webkit-animation-play-state: paused;
animation-fill-mode: forwards;
}
<button type = "button" id= "ST" onclick= "startAnimation()" >Start the story!</button><br><br><br><br>
<p href="#a" id="target">Got this simple problem, but I lack experience in CSS to solve it. Attaching the code below for reference </p>
<audio id="audio" src="https://k15xf2.webwave.dev/lib/k15xf2/Prob1-kgs9f12v.mp3"></audio>
<button type = "button" id= "ST1" onclick= "pauseAnimation()" >Pause the story!</button><br><br><br><br>