Libraryless. Click here for Pure Java version (3104L/21K).
// requires JQuery sS hjs_humWithFade(double humVolume default 0.25) { ret hjs_playHum() + hjs(replaceDollarVars([[ humSound.volume = 0; var humVolume = $humVolume; // 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; hum(humSound.volume); // start playing console.log("hum on (vol=" + humVolume + ")"); fadeHumTo(humVolume); } // TODO: actually turn off in the end function humOff() { if (!humShouldBeOn) return; humShouldBeOn = false; console.log("hum off"); fadeHumTo(0); } function fadeHumTo(vol) { $(humSound).animate({ volume: vol }, { duration: vol < humSound.volume ? 250 : 500, //easing: vol < humSound.volume ? 'easeOutExpo' : 'easeInOutQuint', }); } function updateHumVolume(vol) { if (isNaN(vol) || humVolume == vol) return; humVolume = vol; console.log("New hum volume: " + vol); // fade to new value if (humShouldBeOn) { humShouldBeOn = false; humOn(); } } ]], +humVolume); }
Began life as a copy of #1028691
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1028692 |
Snippet name: | hjs_humWithFade |
Eternal ID of this version: | #1028692/16 |
Text MD5: | ff47cdaa2a297480abe2c154af3c2bcc |
Transpilation MD5: | 4f4130464ad77b5b40d4d3fdaa185baa |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-07-05 17:51:51 |
Source code size: | 1619 bytes / 54 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 222 / 320 |
Version history: | 15 change(s) |
Referenced in: | [show references] |