0

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>
1
  • 1
    What event? Post the rest of your code. Commented Jan 20, 2014 at 2:46

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Why the downvote? If this isn't what the OP wants, then please explain what they want. The question isn't very clear so I'm trying to figure it out for them.
Thank you bro, its worked well, and i dont know whos wote down, im unable to vote. :) Thank you again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.