I'm fairly new to web development, just started to learn the javascript.. So beside learning I'm trying to build a web page where the lyrics will be shown inside a p tag, which is synced with an audio file. The subtitle source is given by vet file extension, and with the help of javascript "cuechange" event I'm trying to inject fat text inside that p tag. Till now everything is working fine. But one more thing I wanna add, that is I want to have a fade-in/fadeout effect animation on cue change event listener inside my p tag, means for each sentence of the lyrics I want a fade-in/fadeout animation before and after. I tried to add css animation directly on p element, but that's not really firing it with an event listener. Can anyone help me out about this?
The github link is given below: 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>