Jump to content

Document Object Property 'left' = 'NaN'


watagal

Recommended Posts

Greetings-I snagged the following code from webmonkey site, but it crashes when it tries to get the 'left' property of a <div> element (near the bottom - in red):

function WM_moveTo(daObject, endLeft, endTop, numSteps, delay, endFunction) {/*	WM_moveTo()	Moves an object from its current location to a new location and optionally fires a function when it's done.	Source: Webmonkey Code Library	(http://www.hotwired.com/webmonkey/javascript/code_library/)	Author: Nadav Savio	Author Email: nadav@wired.com	Usage: WM_moveTo('objectName', endingLeft, endingTop, numberOfSteps, delayBetweenSteps (ms), 'functionToFire()'); */	// Declare variables.	var leftInc, topInc, daObj = new Object;	// The first time through, create document.WM.WM_moveTo	if (typeof document.WM == 'undefined'){		document.WM = new Object;		document.WM.WM_moveTo = new Object;	} else if (typeof document.WM.WM_moveTo == 'undefined') {		document.WM.WM_moveTo = new Object;	}	// Store endFunction to execute when the move is finished.	if(endFunction) document.WM.WM_moveTo.endFunction = endFunction;		// Get a good object reference (call it daObj) from WM_checkIn().	// But if we've already done so, don't check it in again.	if (daObject == "sameObj") {		daObj = document.WM.WM_moveTo.daObj;	} else {		daObj = WM_checkIn(daObject);		document.WM.WM_moveTo.daObj = daObj;	}	// If this is the last step, go to the end point and run endFunction.	if (numSteps == 1) {		daObj.left = endLeft;		daObj.top = endTop;		// If an endFunction was set, execute it and then delete it.		if(document.WM.WM_moveTo.endFunction) {			daFunction = document.WM.WM_moveTo.endFunction;			document.WM.WM_moveTo.endFunction = '';			eval(daFunction);		}	} else {		// Otherwise, figure out how far to move.				leftInc = (endLeft - parseInt(daObj.left)) / numSteps;		topInc = (endTop - parseInt(daObj.top)) / numSteps;		// Then move, decrement numSteps, and do it all again.		[b][color="#FF0000"]daObj.left = parseInt(daObj.left) + leftInc[/color];[/b]		daObj.top = parseInt(daObj.top) + topInc;		numSteps--;		setTimeout ('WM_moveTo(\'sameObj\', ' + endLeft + ', ' + endTop + ', ' + numSteps + ', ' + delay + ')', delay);	}}

When I debug it, "daObj.left" equals "NaN" (not a number), so I assume 'left' is an outdated property.I've search for 'javascript document object' and no luck, can someone help me get on the right path?TiA, Gal

Link to comment
Share on other sites

Thats a weird function... but daObj is a blank object (as it was initialized as a new Object()), and has no relation to window.document.The left property is initialized on the line daObj.left = endLeft; - are you sure you are entering a number in that parameter?

Link to comment
Share on other sites

Thats a weird function... but daObj is a blank object (as it was initialized as a new Object()), and has no relation to window.document.
Thanks Synook-I thought that was wierd too, but figured I wasn't smart enough (yet!) to make that determination. Here's the code where I call the function via <a>'s href attributr:
java script:WM_moveTo(\'divSignIn\', 200, 250, 25, 300)

TiA - I'll keep working at it, Gal

Link to comment
Share on other sites

There's code here to set the object:

if (daObject == "sameObj") {		daObj = document.WM.WM_moveTo.daObj;	} else {		daObj = WM_checkIn(daObject);

I don't know what that sets it to though, I don't have any experience using the WM libraries. Make sure your pages are including all of the required WM files. You might also want to open Firebug and write the object out to the console to inspect it. If the left property is something like "100px" and they use parseInt on it then that will set it to NaN, they would have to remove the units before using parseInt.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...