Team:UCLA/anuved verma ucla2014 workspace
From 2014.igem.org
(Difference between revisions)
Anuvedverma (Talk | contribs) |
Anuvedverma (Talk | contribs) |
||
Line 23: | Line 23: | ||
} | } | ||
} | } | ||
+ | } | ||
+ | function moveDiv(obj, distance, speed){ | ||
+ | if(!distance){distance=250;} | ||
+ | if(!speed){speed=500;} //in milliseconds | ||
+ | |||
+ | if(!obj.styel.marginLeft){obj.style.marginLeft= 0 + 'px';} | ||
+ | |||
+ | var timer = null, | ||
+ | startTime = (new Date).getTime(), | ||
+ | elapsed = null, | ||
+ | d = null; | ||
+ | |||
+ | |||
+ | timer = setInterval(function(){ | ||
+ | elapsed = (new Date).getTime - startTime; | ||
+ | if(elapsed < speed){ | ||
+ | //Do animation | ||
+ | d = elapsed/speed*distance; | ||
+ | obj.style.marginLeft = 0 + 'px'; | ||
+ | } | ||
+ | else{ | ||
+ | //Stop animation | ||
+ | clearInterval(timer); | ||
+ | obj.style.marginLeft = distance + 'px'; | ||
+ | } | ||
+ | }, 5); | ||
+ | |||
} | } | ||
var box = document.getElementById('box'); | var box = document.getElementById('box'); | ||
addEvent(box, 'click', function(){ | addEvent(box, 'click', function(){ | ||
- | + | moveDiv(box,250,1000); | |
}) | }) | ||
</script> | </script> | ||
</body> | </body> | ||
</html> | </html> |
Revision as of 20:54, 11 July 2014