Skip to content

Instantly share code, notes, and snippets.

@wheeyls
Last active October 10, 2015 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wheeyls/3638723 to your computer and use it in GitHub Desktop.
Save wheeyls/3638723 to your computer and use it in GitHub Desktop.
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);
};
}
// 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