spacer

home / experts / dhtml / column25
Developer News
Metasploit 3.2 Offers More 'Evil Deeds'
'Thank You Apple. Seriously.'
The Buzz: BlackBerry App Store Seen Next
Logo

Dynamic Headline Fader, Version 2.0
final functions


slideIt()

When Navigator calls slideIt(), elGif is moved down by the pixel value stored in slideInc:
function slideIt(){
    elGif.top += slideInc;
    if (elGif.top >= 0) {elGif.visibility = "hide";return}
    setTimeout("slideIt()",gifInt);
}

If elGif has reached its final position, that is, if its top property no longer has a negative value, then the display text has faded in and is visible. So we hide elGif and return. If not, then slideIt() is called again at the time interval stored in gifInt, and elGif is moved down again. In other words, slideIt() is called, by itself, repeatedly until elGif has completed its journey over elNews.

endIt()

Version 2 introduces the endIt() function, which contains the statements to be executed when the fader has completed all its loops through the array. As we saw previously, it is called by doIt():

function endIt(){
   clearInterval(blendTimer);
   if (endWithFirst) {
      newsCount = 0;
      fadeIt();
   }
   if (replayOnClick) {
      startIndex = endWithFirst ? 2 : 0;
      if (IE4) {
         elFader.title = "Double click to replay";
         elFader.ondblclick = function(){
            this.ondblclick = null;
            this.title = "";
            startIt(startIndex);
         }
      }
      else {
         elFader.captureEvents(Event.DBLCLICK);
         elFader.ondblclick = function(){
            this.releaseEvents(Event.DBLCLICK);
            startIt(startIndex);
			return false;
         }
      }
    }
}

The first task of endIt() is to stop the repeated calls to doIt(), by clearing the interval timer stored in blendTimer. The fader loops are now complete and elFader is displaying the final item created from the array:

clearInterval(blendTimer);

Next, endIt() checks the value of endWithFirst. If it is true, then the author intends for the first fader item to be displayed after looping is completed. To achieve this, newsCount is set to 0, to point to the beginning of the array, and fadeIt() is called to display the first item. If endWithFirst is false, endIt() does nothing:

if (endWithFirst) {
   newsCount = 0;
   fadeIt();
}

Finally, endIt() checks the value of replayOnClick. If replayOnClick is false, endIt() does nothing and our script execution is finished. If, however, replayOnClick is true, endIt() has a little more work to do.

Since a replay is called for, endIt() must determine from which item to start replaying the fader. The array index representing that item's display text is assigned to startIndex. If endWithFirst is true, meaning the first item is visible, the replay must begin with the second item. The second item is created by the third (index 2) and 4th array elements, so startIndex is assigned a value of 2. If endWithFirst is false, the final item is visible, and the replay should begin with the first item, so startIndex is assigned 0:

startIndex = endWithFirst ? 2 : 0;

The code used to set up the replay is different for the two browsers. For Explorer, we create a popup tooltip using elFader's title property. The title property has been discussed extensively in DHTML Diner. If the user mouses over the fader, the message "Double click to replay" will appear

   if (IE4) {
      elFader.title = "Double click to replay";
      elFader.ondblclick = function(){
         this.ondblclick = null;
         this.title = "";
         startIt(startIndex);
      }
   }

We then set elFader's ondblclick event handler by assigning a function to it. This function will be called whenever the user double clicks on the fader. It first cancels further double click handling by nulling the ondblclick handler. We don't want the fader to respond to double clicks while the transitions are in progress. Then the title property is assigned an empty string for the same reason. Finally, startIt() is called to begin looping through the array with startIndex as its argument.

For Navigator, the ondblclick event handler does nothing unless the event is captured first. So we tell elFader to capture the event:

elFader.captureEvents(Event.DBLCLICK);

Next, we assign a function to the ondblclick handler. When called, the function stops capturing the event, by releasing it. Then startIt() is called:

     elFader.ondblclick = function(){
         this.releaseEvents(Event.DBLCLICK);
         startIt(startIndex);
         reurn false;
      }
Note:
If you set replayOnClick to true, make sure that the visible fader item is not a link. Otherwise, of course, the link will be followed upon the user's first click. The fader on the left demonstrates a good use for both endWithFirst and replayOnClick. They are both set to true. Notice that the first item is a like a title, which introduces the source of the items to follow. This title is not a link and is the item visible when all loops are completed. Double-clicking starts the looping process again without following a link.

Well, that's it for our fader. Some final comments on the next page.


Produced by Peter Belesis and



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview · Controllers: Programming Application Logic - Part 2 · How to Use JavaScript to Validate Form Data
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Choosing the Right Online Backup Provider · Mother Avaya Nurtures Her Technology Partners · Software as a Service a Winning Model for Hotspot Provider

All Rights Reserved. Legal Notices.
Created: Sep 07, 1999
Revised: Sep 07, 1999

URL: http://www.webreference.com/dhtml/column25/fade2end.html