Skip to content

Instantly share code, notes, and snippets.

@jaydenlin
Created July 30, 2014 00:29
Show Gist options
  • Save jaydenlin/e9ffeab9282f0185f0ad to your computer and use it in GitHub Desktop.
Save jaydenlin/e9ffeab9282f0185f0ad to your computer and use it in GitHub Desktop.
Test nomarlized
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<style>
#box{
width:100px;
height:100px;
border-radius:100px;
background-color:blue;
position:absolute;
}
</style>
<div id="box" style="left:0px">
</div>
<script>
$(document).ready(function(){
var box=document.getElementById('box'),
currentTime,
startTime,
normalized,
duration=1500,
getNormalized=function(c,s,d){
return (c*1-s*1)/d;
},
getCurrentTime=function(){
return new Date().getTime();
},
doMove=function(){
currentTime=getCurrentTime();
normalized=getNormalized(currentTime,startTime,duration)
console.log(normalized);
if(normalized<1){
//animation
box.style.left = parseInt(box.style.left)+1+'px';
setTimeout(doMove,2);
}
};
startTime=getCurrentTime();
doMove();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment