spacer
Yehuda Shiran December 26, 1999
Sharing Behaviors
Tips: December 1999

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

We have shown in previous tips (December 24, 1999, December 23, 1999, and December 25, 1999) how to define a Behavior and associate it with one DHTML element. But the real power of Behaviors is that a single Behavior can be shared by several DHTML elements. By assigning different values to the scriptlet's properties, slightly different behaviors can be achieved. Here is our single Blinking Soccer from Column 22, DHTML Behaviors:

<DIV CLASS="soccer" x="200" y="250" onFifthBlink = "alert('Fifth Blink Point')"><IMG SRC="soccer.gif"></DIV> 

Now, let's add five more soccer balls, in different window's locations. The DIV line stays the same, except that the x and y attributes on each DIV are assigned different values:

<DIV CLASS="soccer" x="50" y="100" onFifthBlink = "alert('Fifth Blink Point')"><IMG SRC="soccer.gif"></DIV>
<DIV CLASS="soccer" x="100" y="150" onFifthBlink = "alert('Fifth Blink Point')"><IMG SRC="soccer.gif"></DIV>
<DIV CLASS="soccer" x="150" y="200" onFifthBlink = "alert('Fifth Blink Point')"><IMG SRC="soccer.gif"></DIV>
<DIV CLASS="soccer" x="200" y="250" onFifthBlink = "alert('Fifth Blink Point')"><IMG SRC="soccer.gif"></DIV>
<DIV CLASS="soccer" x="250" y="300" onFifthBlink = "alert('Fifth Blink Point')"><IMG SRC="soccer.gif"></DIV>

Sharing a single module by several elements is one of the cornerstones of any object-oriented languages. It is more than calling a procedure with different arguments. Object-oriented modules encapsulate both data and methods that can operate on this data. Behaviors are exactly that.


People who read this tip also read these tips:

Look for similar tips by subject:


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger