August 17, 2000 - Dynamic Style Evolution
August 17, 2000 Dynamic Style Evolution Tips: August 2000
Yehuda Shiran, Ph.D.
|
Internet Explorer 4.0 and Netscape Navigator 4.0 brought the second revolution. No longer need styles stay fixed while reading the page. These browsers provide the ability to dynamically change any HTML attribute of any element, any time. Attributes can be modified by a JavaScript script, in response to certain events such as the user moving the mouse over the target element. Internet Explorer 4.0 implemented the style specifications as an element property (style
) which is in itself an object. The style
object's properties include all the style attributes such as colors, fonts, spacing, indentation, position, and text's visibility. To change the appearance of an element on the page, you simply change the corresponding property of the style
object. You may also change a direct attribute of an HTML element. For example, you can switch the image of an IMG
element, by setting its SRC
attribute to a different GIF file.
Internet Explorer 5 and later supports dynamic properties, which allow Web authors to assign elements, properties, and formulas to DHTML properties. Dynamic properties are set by the setExpression()
method. You can force recalculation of all expressions by calling the recalc()
method. Learn more about dynamic properties in Column 65, Dynamic Properties. Sometimes, you want to be notified when a dynamic property changes. Elements fire the propertyChange
event (handled by the onPropertyChange()
event handler) when either an object, an expando
, or an object's style changes. (expando is a property of the document
object and it can be either retrieved or set. When set to true
, new properties can be added to objects. When set to false
, no new properties can be added to objects.) Use the onPropertyChange()
event handler and the currentStyle
object to respond to changes throughout a document.
Learn more about the subject in Column 66, Dynamic Styles.