making audio fade on click event
<p>In my game I want the background music to fade away when the "start-btn" is clicked. At the moment it works, but only if the music has been playing for a short period of time. If you leave the music to play for a while it doesn't seem to fade away when the button is clicked.</p>

<pre><code>$(".start-btn-wrapper").click(function() {
    startplay();
    $(bgMusic).on('timeupdate', function() {
        var vol = 1,
            interval = 100;
        if (Math.floor(bgMusic.currentTime) == 5) {
            if (bgMusic.volume == 1) {
                var intervalID = setInterval(function() {
                    if (vol &gt; 0) {
                        vol -= 0.05;
                        bgMusic.volume = vol.toFixed(2);
                    } else {
                        clearInterval(intervalID);
                    }
                }, interval);
            }
        }
    });
});
</code></pre>

<p>Where am I going wrong?</p>
