|
www.insideDHTML.com
Inside Dynamic HTML | Fun and Games | The 10K Demo | XML Online | CSS Online | Resources Write Once! | DHTML Toolkits | Inside Techniques | Inside Scriptlets |
|
moveo() Function The moveo() function moves any CSS positioned element around the screen. To use this function, you need to first define an element with a unique ID and the POSITION, TOP and LEFT style properties defined.
For example, if the POSITION is set to ABSOLUTE, then the element is positioned offset from its contained coordinate system:
When you call the moveo(i, x, y, a) function, i is the element, x is the finishing horizontal (LEFT) coordinate, y is the finishing vertical (TOP) coordinate and a is the number of pixels to move per milisecond. To move the above DIV to 100 pixels over and 20 pixels down: moveo("myDiv", 100, 20, 2) If the element has RELATIVE positioning, then the element is offset from where the element normally appears in the document. Using the moveo function with relative positioning allows you to animate portions of your page onto the screen. Below is a complete example using relative positioning that moves the elements from offscreen into their position in the document.
moveo() Function
function moveo(i, y, x, a) {
yNow = i.style.posLeft;
xNow = i.style.posTop;
var b = a - 1;
if (yNow > (y + b)) {
yNow = yNow - a;
i.style.posLeft = yNow;
} else if (yNow < (y - b)) {
yNow = yNow + a;
i.style.posLeft = yNow;
} else {
yNow = y;
i.style.posLeft = yNow;
}
if (xNow > (x + b)) {
xNow = xNow - a;
i.style.posTop = xNow;
} else if (xNow < (x - b)) {
xNow = xNow + a;
i.style.posTop = xNow;
} else {
xNow = x;
i.style.posTop = xNow;
}
if (yNow == y && xNow == x) {
return;
}
ab1 = window.setTimeout("moveo("+i.id+","+y+","+x+","+a+");", 1);
}
Copyright © 1997-98 InsideDHTML.com, LLC. |