spacer
Yehuda Shiran August 8, 2000
The recalc() Method
Tips: August 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

In JavaScript, you can force a recomputation by calling the Document Object's recalc() method:

document.recalc(true);

In Column 65, Dynamic Properties, we showed how to program the Solar System. We need to trigger a recalculation because the expression we bound to the planets' parameters depends on the time in seconds passed from the initial loading of the page. The time give us a measure of the angle that the planet needs to complete. We need to find out how many seconds have passed every time interval, so we can update the angle (and the planet location) continuously. Here is the functional dependency between the angle and the time, as well as the planet's period length in days:

function angle(periodInDays, t) {
  return ((t / seconds2daysFactor) / periodInDays) % (2 * Math.PI);
}

The planets' xLocation and yLocation depend on the angle. Here is the functional dependency of xLocation:

function xLocation(obj, distanceFactor, daysPerRound, t) {
  return (obj.style.pixelLeft + obj.style.pixelWidth / 2) +   
    Math.round(Math.cos(angle(daysPerRound, t)) * distanceFactor 
	                           * fRadius * distanceOfEarth);
}

We trigger the evaluation by calling the setInterval() function:

intervalID = setInterval("triggerRecalculation()", frequencyOfRecalc);

where triggerRecalculation() is:

function triggerRecalculation() {
  currentTime = new Date() - timeAt0;
  document.recalc(true);
}

For more on Dynamic Properties, go to Column 65, Dynamic Properties.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint