Request Animation Frame
var DURATION = 1000
var startTime = null;
var step = function(currentTime) {
if (startTime == null) {
startTime = currentTime;
}
var fraction = (currentTime - startTime) / DURATION;
var theDiv = document.getElementById('theDiv');
theDiv.style.opacity = interp(0, 1, fraction) + '';
if (fraction < 1.0) {
window.requestAnimationFrame(step);
}
}