PDA

View Full Version : Resolved flying plane script speed and positioning



davelf
02-21-2012, 04:23 AM
1) Script Title: flying plane script

2) Script URL (on DD): http://dynamicdrive.com/dynamicindex4/plane.htm

3) Describe problem:
1. i have problem with the speed, how to set it at the exact speed, '100', '200', etc. Because now everything is random.
2. i want to set position at the header only like the screenshot, but know it fly all around the page.
http://www.dynamicdrive.com/forums/attachment.php?attachmentid=4365&stc=1&d=1329798181

Thank you so much

vwphillips
02-21-2012, 11:28 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<style type="text/css">
/*<![CDATA[*/

#plane {
position:absolute;z-Index:101;left:0px;top:50px;width:100%;height:50px;
}

#plane IMG {
position:absolute;left:100px;top:0px;width:100px;height:50px;
}

#plane2 {
position:absolute;z-Index:101;left:0px;top:250px;width:100%;height:50px;
}

#plane2 IMG {
position:absolute;left:100px;top:0px;width:100px;height:50px;
}

/*]]>*/
</style></head>

<body>
<div id="plane" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/One.gif" alt="plane" width="100" height="50" />
</div>

<div id="plane2" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/Two.gif" alt="plane" width="100" height="50" />
</div>
<script type="text/javascript">
/*<![CDATA[*/

var fly={

init:function(id,i){
var oop=obj=document.getElementById(id),img=obj.getElementsByTagName('IMG')[0],w=img.width;
obj.style.visibility='hidden';
obj.style.overflow='hidden';
img.style.visibility='visible';
img.style.left=-w+'px';
this[id]={
obj:obj,
img:img,
srt:-w,
lft:-w,
i:typeof(i)=='number'?i:5
}
setInterval(function(){ fly.fly(id); },50);
},

fly:function(id){
var oop=this[id];
oop.lft+=oop.i;
if (oop.lft>oop.obj.offsetWidth){
oop.lft=oop.srt;
}
oop.img.style.left=oop.lft+'px';

}

}

fly.init('plane',5);
fly.init('plane2',2);
/*]]>*/
</script>
</body>

</html>

davelf
02-22-2012, 03:22 AM
@Vic You're the best