Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving Objects

Status
Not open for further replies.

Detlef

Technical User
Apr 3, 2001
8
0
0
DE
Hi,
I´m looking for a script to move several objects at the
same time at slow speed. To move 1 object is no problem. But I can´t manage to move more.
Anybody´s got an idea or a script?
 
well, then u shuld use loop:
smth like this:
var movinobjs=new Array(&quot;l1&quot;,&quot;l2&quot;,&quot;l3&quot;)//<--id's of ur layers
for (var ii=0; ii<movinobjs.length; ii++){
var temp=eval(&quot;document.all.&quot;+movinobjs[ii]+&quot;.style&quot;)
temp.left-=10
}


got it? its simple.. ;-)

regards, vic
 
Sorry, can´t manage that.
I´v got a script here which works with one layer. I did a
workaround using a timout; but that´s not what I want.
Maybe you could help me with this one:

<HTML>
<HEAD>

<script language=&quot;JavaScript&quot;>
<!--
IE4 = navigator.appName == &quot;Microsoft Internet Explorer&quot; && parseInt(navigator.appVersion) >= 4;
NS4 = navigator.appName.substring(0,8) == &quot;Netscape&quot; && parseInt(navigator.appVersion) >= 4;

// checkBrowser() -- Checks whether the browser is new enough for some DynamicMovement ...

function checkBrowser(){
if(IE4 || NS4){
return true;
}
return false;
}

// movableObj() -- Creates a new movable object

function movableObj(startX, startY, endX, endY, delay, speed, refId){
this.sX = startX; this.sY = startY; this.eX = endX;
this.eY = endY; this.de = delay; this.sp = speed;
this.ref = refId;
xL = endX - startX;
yL = endY - startY;
with (Math){
if(abs(xL) > abs(yL)){
this.xS = (xL > 0)?1:-1;
this.yS = (yL > 0)?abs(yL / xL):-abs(yL / xL);
this.howManySteps = abs(xL / speed);
} else if(abs(yL) > abs(xL)){
this.yS = (yL > 0)?1:-1;
this.xS = (xL > 0)?abs(xL / yL):-abs(xL / yL);
this.howManySteps = abs(yL / speed);
} else {
this.yS = (yL > 0)?1:-1;
this.xS = (xL > 0)?1:-1;
this.howManySteps = abs(xL / speed);
}
}
this.startMovement = startMovement;
}

// startMovement() -- starts the movement

function startMovement(){
if(checkBrowser()){
if(IE4){
ref = document.all(this.ref).style;
} else {
ref = document[this.ref];
}
doDynamicMovement(this.sX, this.sY, this.eX, this.eY, this.de, this.xS, this.yS, ref, this.sp, this.howManySteps);
}
}

// doDynamicMovement() -- does the Dynamic Movement

function doDynamicMovement(curX, curY, eX, eY, sp, xS, yS, ref, speed, hS){
if(Math.floor(hS - 1) != 0){
hS--;
curX += xS * speed;
curY += yS * speed;
ref.left = Math.round(curX);
ref.top = Math.round(curY);
setTimeout(&quot;doDynamicMovement(&quot; + curX + &quot;, &quot; + curY + &quot;, &quot; + eX + &quot;, &quot; + eY + &quot;, &quot; + sp + &quot;, &quot; + xS + &quot;, &quot; + yS + &quot;, ref, &quot; + speed + &quot;, &quot; + hS + &quot;)&quot;, sp);
} else {
setPos(eX, eY, ref);
}
}

// setPos() -- sets the end position accurately when doDynamicMovement has done its job

function setPos(x, y, ref){
ref.left = x;
ref.top = y;
}

function anfang(){
Bild1.startMovement();
setTimeout(&quot;Bild2.startMovement()&quot;, 1500);
setTimeout(&quot;Bild3.startMovement()&quot;, 2500);
setTimeout(&quot;Bild4.startMovement()&quot;, 4000);
}
// -->
</script>

</HEAD>

<BODY onLoad=&quot;anfang()&quot; bgcolor=&quot;white&quot;>


<div id=&quot;bild1&quot; style=&quot;position: absolute; left: -300; top: -150; width: 150px;
height: 150px&quot;><img src=&quot;1_1.jpg&quot; width=&quot;150&quot; height=&quot;150&quot;> </div>

<div id=&quot;bild2&quot; style=&quot;position: absolute; left: 300; top: -150; width: 150px;
height: 150px&quot;><img src=&quot;1_2.jpg&quot; width=&quot;150&quot; height=&quot;150&quot;> </div>

<div id=&quot;bild3&quot; style=&quot;position: absolute; left: 900; top: -150; width: 150px;
height: 150px&quot;><img src=&quot;1_3.jpg&quot; width=&quot;150&quot; height=&quot;150&quot;> </div>

<div id=&quot;bild4&quot; style=&quot;position: absolute; left: 1200; top: -150; width: 150px;
height: 150px&quot;><img src=&quot;1_4.jpg&quot; width=&quot;150&quot; height=&quot;150&quot;> </div>

<script language=&quot;JavaScript&quot;>
<!--

// Here we define the movable object
Bild1 = new movableObj(-300,-150,150,100,20,20,&quot;bild1&quot;);
Bild2 = new movableObj(300,-150,300,100,20,20,&quot;bild2&quot;);
Bild3 = new movableObj(900,-150,450,100,20,20,&quot;bild3&quot;);
Bild4 = new movableObj(1200,-150,600,100,20,20,&quot;bild4&quot;);
// -->
</script>

</BODY>
</HTML>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top