Reputation: 5
Can anyone tell me how to return event, This is a button that SKIP song, and this make sound stop gradually, but when song changed the volume is 0 and cant hear nothing, how to make it to 1 again after event finnished?
<script>
function fadeOut() {
var volume = 1;
var fade = setInterval(function () {
api_setVolume(players[0], volume);
volume -= .1;
if (volume === 0)
clearInterval(fade);
}, 1000);
}
</script>
<a href='javascript:void(0)' onClick="fadeOut();">Fade Out</a>
Upvotes: 0
Views: 102
Reputation: 707158
If I understand what you're asking, you can just set the volume back to 1 when it gets to zero and you stop your interval. If this isn't what you want, then please explain what you mean by "after the event is finished".
<script>
function fadeOut() {
var volume = 1;
var fade = setInterval(function () {
api_setVolume(players[0], volume);
volume -= .1;
if (volume <= 0) {
clearInterval(fade);
api_setVolume(players[0], 1);
}
}, 1000);
}
</script>
Also, checking a volume===0
is very dangerous with floating points values. You should check for <= 0
.
Upvotes: 2