I used a linear interpolation function to achieve this effect. It could be done so much simpeler but hey, Math!
Created
November 2, 2014 20:20
-
-
Save cythux/be4a090caef78740fd30 to your computer and use it in GitHub Desktop.
A Pen by Ritchie.
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
<div id="box"></div> |
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 appr(goal, current, time){ | |
if(current < goal){ | |
return current + time; | |
}else{ | |
return goal; | |
} | |
} | |
function point(x, y){ | |
this.x = x; | |
this.y = y; | |
} | |
var box = document.getElementById('box'); | |
var crp = new point(0.0, 0); | |
var p = new point(1.0, 100); | |
setInterval(function(){ | |
crp.x = appr(p.x, crp.x, 0.015); | |
crp.y = appr(p.y, crp.y, 1.5); | |
box.style.opacity = crp.x; | |
box.style.width = crp.y+"%"; | |
}, 1000/60); |
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
body { margin: 0; background: #1F1F1F;} | |
#box { | |
background: #A55; | |
width: 500px; | |
height: 5px; | |
opacity: 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment