PDA

View Full Version : relative movement animation



jpweeks
04-14-2009, 05:59 AM
I want to animate this location function, any help?

<code>
function setPosition (id,topY,leftX) {
var layerRef = document.getElementById(id);

if (layerRef==null) return;

if (layerRef.style.left && layerRef.style.top) {
layerRef.style.left = leftX+'px';
layerRef.style.top = topY+'px';
}
if (layerRef.style.posLeft && layerRef.style.posTop) {
layerRef.style.posLeft = leftX;
layerRef.style.posTop = topY;
}
}
</code>

vwphillips
04-14-2009, 09:30 AM
http://www.vicsjavascripts.org.uk/AnimatorBasic/AnimatorBasic.htm

jpweeks
04-14-2009, 07:58 PM
The problem i'm having is identifying the div's current position to set as the variable for the animation starting point. I want the div's position to not be stagnant, so the javascript needs to talk to the div to find its current position, then proceed to the designated absolute position on the page which is explicitly identified in the script.

Master_script_maker
04-15-2009, 03:28 AM
use layerRef.offsetTop and layerRef.offsetLeft to find the values.

jpweeks
04-15-2009, 05:41 PM
function Move(){
var obj=document.getElementById('places');
var srt=findPos(obj);
zxcBAnimator('top',obj,srt,-350,2000);
}

function findPos(obj) {
var obj=document.getElementById('places');
var curtop = 0;
if (obj.offsetParent) {

do {
curtop += obj.offsetTop;
}
while (obj = obj.offsetParent);
return [curtop];
}


I'm using this movement animation script 'zxcBAnimator', and trying to identify the position start variable with the 'findPos' function. I'm not sure why this is not working.

jpweeks
04-15-2009, 10:02 PM
nm...I've got it working now