Just starting out with web development and learning JavaScript. Trying to create a webpage that displays lyrics synced with an audio file inside a p tag. The subtitles are sourced from a vet file extension and I am using the "cuechange" event in JavaScript to inject the text into the p tag. Everything is working well so far, but I want to add a fade-in/fade-out animation effect for each sentence of the lyrics when the cue changes. I attempted to add a CSS animation directly to the p element, but it's not triggering with an event listener. Could someone offer guidance on this?
GitHub link: https://github.com/beatzonic/Audio-Lyrics-Subtitle
document.getElementById('my_audio').textTracks[0].addEventListener('cuechange', function() {
document.getElementById('lyric').innerText = this.activeCues[0].text;
});
body{
margin: 0;
padding: 0;
}
#lyrics_container{
width: 100%;
height: auto;
padding: 30px;
box-sizing: border-box;
}
p{
font-size: 2em;
color: red;
font-weight: 600;
}
@keyframes fadein{
0% {
opacity:0;
}
100% {
opacity:1;
}
}
<div id="lyrics_container">
<audio id="my_audio" controls>
<source src="https://github.com/beatzonic/Audio-Lyrics-Subtitle/raw/master/in_case_you_didnt_know.mp3" type="audio/mpeg">
<track id="sub" kind="subtitles" label="English subtitles" src="https://raw.githubusercontent.com/beatzonic/Audio-Lyrics-Subtitle/master/in_case_you_didnt_know.txt.vtt" srclang="en" default>
Your browser does not support the audio tag.
</audio>
<p id="lyric" class="lyrics-class"></p>
</div>