JavaScript
  Home arrow JavaScript arrow Page 2 - Special Effects with DHTML Rollovers
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Special Effects with DHTML Rollovers
By: Ian Felton
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 17
    2004-09-28

    Table of Contents:
  • Special Effects with DHTML Rollovers
  • Enter the JavaScript
  • The Main Effect and Implementation
  • Putting it all Together

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Special Effects with DHTML Rollovers - Enter the JavaScript


    (Page 2 of 4 )

    Next some JavaScript is needed before getting to the body of the HTML document. Since naming conventions are different in Internet Explorer and Netscape when working with JavaScript, a short function is called that determines the type of browser being used. The browser sniff function is used in tandem with another function called standardize which standardizes the way style sheet objects are called with Internet Explorer and Netscape Navigator. The HTML Guru (http://htmlguru.com) provided these functions and both remain useful after six years of using them.

    function browser_Sniff() {
      //Determines which browser and version is being used
      var agent = navigator.userAgent.toLowerCase();
      this.major = parseInt(navigator.appVersion);
      this.minor = parseFloat(navigator.appVersion);
      this.ns = ((agent.indexOf('mozilla')!=-1) &&
    ((agent.indexOf('spoofer')==-1) &&
    (agent.indexOf('compatible') == -1)));
      this.ns2 = (this.ns && (this.major == 3));
      this.ns3 = (this.ns && (this.major == 3));
      this.ns4b = (this.ns && (this.minor < 4.04));
      this.ns4 = (this.ns && (this.major >= 4));
      this.ie = (agent.indexOf("msie") != -1);
      this.ie3 = (this.ie && (this.major == 2));
      this.ie4 = (this.ie && (this.major >= 4));
      this.op3 = (agent.indexOf("opera") != -1);
      this.win = (agent.indexOf("win")!=-1);
      this.mac = (agent.indexOf("mac")!=-1);
      this.unix = (agent.indexOf("x11")!=-1);
    }

    Now we call the function.

    var is = new browser_Sniff();   // Calls Browser sniffing function
    function standardize() {
    // Once browser has been sniffed
    // these conditionals set Netscape and Microsoft syntax
    // to the same variable, so that only one function need be written
    if(is.ns4) {
      doc = "document";
      sty = "";
      htm = ".document"; }
    else if(is.ie4) {
      doc = "document.all";
      sty = ".style";
      htm = "";
    }

    For simplicity sake, assign variables to the style sheet objects that were defined in the beginning. Doing this will save a lot of typing. The Load_Name() function will accomplish that task.

    // Sets variables for image manipulation
    function Load_Name() {  //Creates layer objects
    Centralobj = eval(doc + '["Central"]' + sty);
    Behindobj = eval(doc + '["Behind"]' + sty);
    }

    One more function is required before getting to the actual Shudder function. The Position function places all of the images in the correct location and makes them visible. It finds the available height and width of the page and divides that by 2 to get the center point. If the images were placed on this point, the top-left corner of the images would be in the center point of the screen. Since the image should be centered, pixels are subtracted from the left and top positions to place the images center near the actual center of the screen. Once the images are placed, they are turned to a visible state.

    function Position() {
    Centralobj.left = (available_width / 2) - 211;
    Centralobj.top = (available_height / 2) - 143;
    Centralobj.visibility = 'visible';
    Behindobj.left = (available_width / 2) - 211;
    Behindobj.top = (available_height / 2) - 143;
    Behindobj.visibility = 'visible';
    }

    More JavaScript Articles
    More By Ian Felton


       · Eh, why on earth would you use js for this when you have the :hover css-property? It...
       · Thanks for the post.Hover is useful, but the article was demonstrating how to...
       · Check out the cited example site (http://unitedbands.com/devArticles/shudder.html)...
       · .... doesn't work in Mozilla.
       · The shudder effect was tested on IE 6 and Opera 6.5 where it works fine. I'm sure...
       · Are not really helpful in a web environment that strives for standard compliance and...
       · If I hear one more silly rant about compatibility (which really means homogenizing...
       · Sure it's a neat effect but no rubbish about web standards being a homogenisation...
     

    JAVASCRIPT ARTICLES

    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT