If I wish to change the opacity
of a <div>
irregularly over time, I can use CSS animation
and @keyframes
:
.myDiv {
animation: myAnimation 10s linear;
}
@keyframes myAnimation {
0% {opacity: 1;}
80% {opacity: 1;}
81% {opacity: 0.99;}
100% {opacity: 0;}
}
}
But what if I want to change the volume
of an <audio class="my-audio">
element irregularly over time in an identical manner?
I know I can begin with:
var myAudio = document.getElementsByClassName('my-audio')[0];
myAudio.volume = 1.0;
But how can I change the volume
to 0.99
, when 81%
of the sound clip has played and fade uniformly down to a volume
to 0.0
, when 100%
of the sound clip has played?
Is there a javascript syntax for this kind of aural transition or am I looking for something which doesn't exist (yet)?