as far as i understand it is a giving and taking here in ozones asylim. so now it is my time to give:
this is a function that moves objects around:
it's an api, just suck the information you need out of it...
[hr]
/********************************************************************************************api by Karsten Hiekmann. custom objects ********************************************************************************************/
/*******************************************************************************************
start of api**********************************************************************************/
//ERROR TRAPPING CODE -- this is an error trapping code. doesn't work in NN though....
window.onerror=null;
//browser sniffer. but no Mozilla
function checkb()
{
this.ver = navigator.appVersion
this.ie = (document.all) ? 1:0;
this.n = (document.layers) ? 1:0;
this.ie4 = (this.ver.indexOf('MSIE 4')>0);
this.ie4mac = this.ie4 && navigator.userAgent.indexOf("Mac")>-1;
this.ok = (this.ie | | this.n) && (!this.ie4mac);
return this
}
br=new checkb();
//alert(br.ver);alert(br.ie);alert(br.n);alert(br.ie4);alert(br.ie4mac);alert(br.ok); -- I used this one
//to find out about my own 3 browsers(!)
//object constructor. -- makes an object. VERY nice thing. needs some special attention! (*SA)
function makeObj(id,nest)
{
if (br.n)
{
nest=(!nest) ? '':'document.'+nest+'.';
this.css = eval(nest+"document.layers." +id);
this.x = this.css.left;
this.y = this.css.top;
this.w = this.css.document.width
this.h = this.css.document.height;
}
if (br.ie)
{
this.elm = document.all[id];
this.css = document.all[id].style;
this.x = this.elm.offsetLeft;
this.y = this.elm.offsetTop;
this.w = this.elm.offsetWidth;
this.h = this.elm.offsetHeight;
}
this.obj = id+'Object';
eval (this.obj +' =this');
return this;
}
/********************************************************************************************
index****************************************************************************************/
function index1(theObj,px,py,pjx,pjy,pex,pey,wait,sc)
// ok, some explaining here:
//you would acces this function by using unload in the body tag. :
//<body onload=index1('idofdiv','outleft',0,5,5,'center',100,1)
//theObj is the id of the div (a string at this point). px and py are starting points of the div.
//pjx and pjy are the values the object jumps at each interval.
//pex, and pey are the coordinates where the div stops. x is left (0) to right and y is top (0) to bottom
//the beauty of this program is that you can insert string like center and right and the programm finds the
// coordinates on its own;
//wait is the for the timeout settings. how long it waites before removing it. in millisecs and the smaller the
//faster
//sc is another sweet thing. it stands for shortCut. it calculates the straight line between 2 points! 1 means you
// want it 0 means... hard to explain.. check it out....
{
px=getPos(theObj,px); //in the case you used presettings like 'center' it will check it out now.
py=getPos(theObj,py); //dito
pex=getPos(theObj,pex); //dito
pey=getPos(theObj,pey); //dito
var fs=true; //stands for firstSlide... i'll tell you later...
if(sc==1) //check out if you want a shortcut and calculates it
{
var tempx=(pex-psx)/pjx;
var tempy=(pey-psy)/pjy;
//the ending point minus the start point are the distance on a axis. divided by the jumpdistance gives
//you the amount of jumps.
if(tempx==tempy){pjx=pjx; pjy=pjy;}
else if (tempx>tempy){pjx=pjx; pjy=(pey-psy)/tempx;}
else if (tempx<tempy){pjx=(pex-psx)/tempy; pjy=pjy;}
else {alert('not defined');}
//here we check for the smaller amount of jumps. if tempx is smaller it has to jump a bigger distance on the y
// axis how do we get that? by dividing the distance of the y axis by the smaller amount of jumps.
}
//alert(pjx + " " + pjy) --used to check if it works
slide(theObj,px,py,pjx,pjy,pex,pey,wait,fs); //let's move it baby!
}
function slide(theObj,px,py,pjx,pjy,pex,pey,wait,fs)
//those are a lot of references, i know, but i'ld hate to make them global if i don;t use it in my api and
//i really don;t like to change everything by hand. this way I'll change the references later in the body-tag
//and don't even bother about my api.js
{
if (fs) //ok, now i tell you. is it in the slide function the first time? (fs) means (fs==true) if yes:
{
fs=false; //it won't be the first time the next time, change fs
shiftTo(theObj,px,py); //send it to shiftTo which positiones the div on the page.)
setTimeout('slide("'+theObj+'" ,'+px+','+py+','+pjx+','+pjy+','+pex+','+pey+','+wait+','+fs+')',wait);
//there is no timeout needed, but i just added it here. it calls the slide function again and sends the
//references. that's the difficult part:
//if the ref is a string send it this way: " '+stringinthiscasidofdiv+' " ( , if there are more)
//if it is a number: '+num+' ( , if there are more)
//it is critical to NOT leave a space after the ' when sending a string. it would add an empty space
//*took me hours to find that error!
}
else //if it is not the first Time anymore
{
if ((px<=pex)&&(py<=pey)) //if the coordinates are smaller than the endcoordinates...
{
px +=pjx; //add the jumpdistance to get the new coordinate ...
py +=pjy; //...for the next jump...
shiftTo(theObj,px,py); // ...change the position now...
setTimeout('slide("'+theObj+'",'+px+','+py+','+pjx+','+pjy+','+pex+','+pey+','+wait+','+fs+')',wait);
//and wait a little bit before you do it again... easy!
}
else if ((px>pex)&&(py<=pey)) //what if one coordinate already passed the limit-value?
{
py +=pjy; //just add to the value which still is smaller
shiftTo(theObj,px,py); //send it
setTimeout('slide("'+theObj+'",'+px+','+py+','+pjx+','+pjy+','+pex+','+pey+','+wait+','+fs+')',wait);
//and wait
}
else if ((px<=pex)&&(py>pey)) //mostly the same as above
{
px +=pjx; shiftTo(theObj,px,py);
setTimeout('slide("'+theObj+'",'+px+','+py+','+pjx+','+pjy+','+pex+','+pey+','+wait+','+fs+')',wait);
}
else {alert('DANG IT!';} //well, now you know it didn;t work!
}
}
/*********************************************************************************************
Utilitiy functions*****************************************************************************/
function shiftTo(theObj,x,y) //What about a shiftBy?--note for myself...
//Positioning an object at a specific pixel coordinate
{
var obj=new makeObj(theObj); //make the div id an object
if (typeof x != "number") {x=getPos(theObj,x)} //checks if it is a string (that's the beauty...) or a number
if (typeof y != "number") {y=getPos(theObj,y)} //and gets the right values if it is
obj.css.left = x;
obj.css.top = y; //assigns the new coordinates to the obj.
}
function getPos(theObj,pos)
//this one converts the strings into numbers whith which the pc can work... browser i mean.
{
var obj=new makeObj(theObj); //make div id an object
var page = new pageSize; //get the page sizes
if (typeof pos == "number") {pos=pos;} // if it is a number dont'change it
//positions on the x axis.
//you can have those kinds of strings:
else if (pos=="outleft"){pos=0-obj.w;} //outleft is left of the window by a object width
else if (pos=="left"){pos=0;}//left
else if (pos=="center"){pos=(page.w-obj.w)/2;}//windowwidth-objectwidth divided by 2 to center it
else if (pos=="right"){pos=page.w-obj.w;}//windowwidth-objectwidth
else if (pos=="outright"){pos=page.w+obj.w;}//on the right side of the window.
//positions along the y axis.
else if (pos=="outtop"){pos=0-obj.h;}//you get the idea...
else if (pos=="top"){pos=0;}
else if (pos=="middle"){pos=(page.h-obj.h)/2;}
else if (pos=="bottom"){pos=page.h-obj.h;}
else if (pos=="outbottom"){pos=page.h+obj.h;}
else {alert('not defined');}
return pos;
}
function pageSize()
//window: inner Width&Height and middle,center
{
this.w = (br.n) ? innerWidth:document.body.offsetWidth;
this.h = (br.n) ? innerHeight:document.body.offsetHeight;
this.w2 = this.x/2;
this.h2 = this.y/2;
return this
}
[hr]
thanks to bitdamaged because the makeObject-Idea came from him. and shadowimage he showd me the refernece thing.
and thanks to the others.
I will add better versions like not having to add - signs in front of the jumpvalue in the body tag
as soon you want it to slide up or left...
k10