Team:UCLA/anuved verma ucla2014 workspace

From 2014.igem.org

(Difference between revisions)
Line 14: Line 14:
function addEvent(obj,evt,fn,capture){
function addEvent(obj,evt,fn,capture){
evt=evt.replace('on','');
evt=evt.replace('on','');
-
if(obj.attachEvent){
+
if(obj.attachEvent) obj.attachEvent('on'+ evt,fn);
-
obj.attachEvent('on'+ evt,fn);
+
-
}
+
else{
else{
-
if(!capture){
+
if(!capture)
capture=false;
capture=false;
-
obj.addEventListener(evt,fn,capture);
+
obj.addEventListener(evt,fn,capture);
-
}
+
}
}
}
}
-
function moveDiv(obj, distance, speed){
+
function moveDiv(obj,distance,speed){
-
if(!distance){distance=250;}
+
if(!distance)
-
if(!speed){speed=500;} //in milliseconds
+
distance=250;
-
+
if(!speed)
-
if(!obj.styel.marginLeft){obj.style.marginLeft= 0 + 'px';}
+
speed=500;
-
+
if(!obj.style.marginLeft)
-
var timer = null,
+
obj.style.marginLeft=0+'px';
-
startTime = (new Date).getTime(),
+
var timer=null,
-
elapsed = null,
+
startTime=(new Date).getTime(),
-
d = null;
+
elapsed=null,
-
+
d=null,
-
+
dir='right',
-
timer = setInterval(function(){
+
current_distance=obj.style.marginLeft.replace('px','');
-
elapsed = (new Date).getTime - startTime;
+
if(distance<current_distance)
-
if(elapsed < speed){
+
dir='left';
-
//Do animation
+
timer=setInterval(function(){
-
d = elapsed/speed*distance;
+
elapsed=(new Date).getTime()- startTime;
-
obj.style.marginLeft = 0 + 'px';
+
if(elapsed<speed){
 +
if(dir=='right'){
 +
d=elapsed/speed*distance;
 +
obj.style.marginLeft=d+'px';
 +
}
 +
else{
 +
d=elapsed/speed*distance;
 +
d=current_distance- d;
 +
obj.style.marginLeft=d+'px';
 +
}
}
}
else{
else{
-
//Stop animation
 
clearInterval(timer);
clearInterval(timer);
-
obj.style.marginLeft = distance + 'px';
+
obj.style.marginLeft=distance+'px';
}
}
-
}, 5);
+
},5);
-
+
}
}
var box = document.getElementById('box');
var box = document.getElementById('box');

Revision as of 20:59, 11 July 2014

iGEM UCLA