Last active
October 10, 2015 05:08
-
-
Save wheeyls/3638723 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tween(start, end, fn) { | |
var duration = end - start | |
; | |
fn = fn || function (v) { return v; }; | |
return function (continuation, now) { | |
var relativeNow = now - start | |
, normalNow | |
, res | |
; | |
normalNow = duration === 0 ? -1 : relativeNow / duration; | |
if (normalNow < 0) { | |
res = 0; | |
} else if (normalNow > 1) { | |
res = 1; | |
} else { | |
res = fn(normalNow); | |
} | |
continuation(res); | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 30s to 60s | |
var intermission = tween(30, 60); | |
function fadeColor(evt) { | |
var time = evt.target.currentTime | |
, startingSaturation = 80 | |
; | |
intermission(function (value) { | |
var s = startingSaturation + value; | |
document.body.style.background = 'hsl(15, ' + s + '%, 40%)'; | |
}, time); | |
} | |
document.getElementsByTagName('audio') | |
.addEventListener('timeupdate', fadeColor, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment