Libraryless. Click here for Pure Java version (3104L/21K).
1 | // requires JQuery |
2 | sS hjs_humWithFade(double humVolume default 0.25) { |
3 | ret hjs_playHum() |
4 | + hjs(replaceDollarVars([[ |
5 | humSound.volume = 0; |
6 | var humVolume = $humVolume; // level when on |
7 | var humShouldBeOn = false; |
8 | |
9 | $.extend($.easing, { |
10 | easeOutExpo: function(x, t, b, c, d) { |
11 | return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; |
12 | }, |
13 | easeInOutQuint: function (x, t, b, c, d) { |
14 | if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; |
15 | return c/2*((t-=2)*t*t*t*t + 2) + b; |
16 | } |
17 | }); |
18 | |
19 | function humOn() { |
20 | if (humShouldBeOn) return; |
21 | humShouldBeOn = true; |
22 | hum(humSound.volume); // start playing |
23 | console.log("hum on (vol=" + humVolume + ")"); |
24 | fadeHumTo(humVolume); |
25 | } |
26 | |
27 | // TODO: actually turn off in the end |
28 | function humOff() { |
29 | if (!humShouldBeOn) return; |
30 | humShouldBeOn = false; |
31 | console.log("hum off"); |
32 | fadeHumTo(0); |
33 | } |
34 | |
35 | function fadeHumTo(vol) { |
36 | $(humSound).animate({ volume: vol }, { |
37 | duration: vol < humSound.volume ? 250 : 500, |
38 | //easing: vol < humSound.volume ? 'easeOutExpo' : 'easeInOutQuint', |
39 | }); |
40 | } |
41 | |
42 | function updateHumVolume(vol) { |
43 | if (isNaN(vol) || humVolume == vol) return; |
44 | humVolume = vol; |
45 | console.log("New hum volume: " + vol); |
46 | |
47 | // fade to new value |
48 | if (humShouldBeOn) { |
49 | humShouldBeOn = false; |
50 | humOn(); |
51 | } |
52 | } |
53 | ]], +humVolume); |
54 | } |
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: | 225 / 325 |
Version history: | 15 change(s) |
Referenced in: | [show references] |