␡
- Creating a Custom Effects Object
- Adding a Fade Method to the Object
- Using the Fade Method
- More to Come
Using the Fade Method
To use the Effects object, we must first import the JavaScript object that we just finished creating. To do so, we type the appropriate path to the object:
<script type="text/javascript" src="path to.../Effects.js"></script>
Once the object is imported, we can simply call its fade method and pass the correct parameters. It’s really that easy:
<img src="images/dscf0298.jpg" id="img1" border="0" onload="Effects.fade(’img1’, 0, 100, 1000, ’Effects.onFaded()’);" />
When the image loads, we simply fire the fade method, passing the ID, the starting and ending opacity percentages, the duration as milliseconds, and (optionally) the callback method. It doesn’t get much easier than that.