A Complete Guide to Web Design

(やまだぃちぅ) #1
DHTML Examples 439

DHTML

DHTML Examples

Web Design in a Nutshell, eMatter Edition

if ( navigator.appName == "Microsoft Internet Explorer" )
{
isIE4 = true;
}
}
// End the browser detection script.

After detecting the browser, we write amotionfunction, customized for each
browser withifstatements. This function accesses theanimateobject and adds 2
to itsleftattribute. After adding 2, it checks to see if the object’sleftattribute is
greater than 200. If so, the animation stops.


// Variable through which timed events will be accessed.
var counter;

function motion()
{
if (isNet4)
{
// Move the animate object 2 pixels to the left
document.animate.left += 2;

// Check to see if the animate object is 200 pixels
// into the page. If it is, execute the script between
// the brackets.
if (document.animate.left > 200)
{
// End the animation.
clearTimeout(counter);
}
}

if (isIE4)
{
// Move the animate object 2 pixels to the left
document.all.animate.style.pixelLeft += 2;

// Check to see if the animate object is 200 pixels
// into the page. If it is, execute the script between
// the brackets.
if (document.all.animate.style.pixelLeft > 200)
{
// End the animation.
clearTimeout(counter);
}
}
}
</script>

The onloadevent passes the value setInterval('motion()', 20) to the
counter. Once this is set, themotionfunction will automatically execute every 20
milliseconds until stopped with theclearTimeout function.

Free download pdf