// requires JQuery sS hjs_humWithFade() { ret hjs_playHum() + hjs([[ humSound.volume = 0; var humVolume = 0.25; // level when on var humShouldBeOn = false; $.extend($.easing, { easeOutExpo: function(x, t, b, c, d) { return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; }, easeInOutQuint: function (x, t, b, c, d) { if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; return c/2*((t-=2)*t*t*t*t + 2) + b; } }); function humOn() { if (humShouldBeOn) return; humShouldBeOn = true; print("hum on"); fadeHumTo(humVolume); } // TODO: actually turn off in the end function humOff() { if (!humShouldBeOn) return; humShouldBeOn = false; print("hum off"); fadeHumTo(0); } function fadeHumTo(vol) { $(humSound).animate({ volume: vol }, { duration: vol < humSound.volume ? 250 : 500, easing: vol < humSound.volume ? 'easeOutExpo' : 'easeInOutQuint'/*'easeInExpo'*/, step: function(value) { hum.volume = value; } }); } ]]); }