The function called Dynamic HTML Behaviors was first released with version 5 of Microsoft's Internet Explorer. The process makes Dynamic HTML functionality more accessible and easier to use in a document. A DHTML behavior component can be written in many scripting languages, including JScript or VB Script, and supplies dynamic functionality that can be applied to any element in an HTML document through the use of Cascading Style Sheets (CSS).
You may have noticed as the page finished loading how these annoying flies did what flies do. DHTML behaviors like this use CSS to separate the script from the content and style of documents. Isolating functionality in this way is known to developers as "encapsulation," it brings the benefits of object reuse to the world of DHTML.
So how do you declare and use DHTML behaviors in a Web page? If you know how to use CSS, you know how to use DHTML behaviors. It really is that easy. As proposed to the World Wide Web Consortium (W3C) by Microsoft, a new CSS property called behavior would define the location of the behavior component. Be forewarned that behaviors are merely a proposal, are not a part of any Document Object Model standard, and are only available with Internet Explorer. More fodder for the browser wars, but what did you expect?
In the sample above, the script that implements the "flyin" effect is encapsulated in a separate file. That is the beauty of behaviors, they reside outside the HTML container. Behaviors are recognized with a Windows extension of .htc, and are supportable by all platform versions since IE5. You may obtain the Microsoft public domain fly.htc (1900 bytes) file here. To use the fly-in behavior on your own site, simply wrap the HTML content to be animated within <IE5:fly> tags as demonstrated below.
Add these <STYLE> tags to the <HEAD> section of your page.
Put these <DIV> tags in the <BODY> section of your page.
<DIV class=fly delay=2000 from=right>
Did you find this tip helpful? Let us know by sending your comments to the email link below. If the sample code above still left you confused, remember the View Source option in your browser.
Proceed to Dynamic HTML Mouse Trails Tutorial (IE only).
Return to Dynamic HTML Transitions Tutorial (IE only).