iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (35)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

September 7, 2008
Web Design Clinic - Art meets Webdesign
About
 
September 6, 2008
Browser safe colors - do we care?
About
 
September 6, 2008
Get a Daily CSS Tip
About
 
September 5, 2008
It's safe to use Google Chrome now
About
 
September 5, 2008
Add a comment
.net
 
September 5, 2008
The Partial Function Application in JavaScript
WebReference.com
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /HTML /DHTML

DHTML Gliding Menu Navigation Bar 

  Views:    8913
  Votes:    2
by Eddie Traversa 4/30/04 Rating: 

Synopsis:

This little script was inspired by a flash navigation effect I saw some time ago. I wondered if I could do the same thing in DHTML and overall I am happy with the outcome.
Pages: firstback1 3 4 forwardlast
The Article

Having set all our global variables we need a way to capture an elements current position. The getPosition() function does just that;

6. function getPosition(id) {
7. if (document.getElementById) {
8. endPos = document.getElementById(id).offsetLeft;
9. }
10. else if (document.layers) {
11. endPos = document.layers[id].left;
12.}
13.}

Line 6:Creates a function called getPosition() and utilises an id argument as a parameter that will be passed to this function at the event handler point.

Line 7:Specifies a condition. If the browser meets the document.getElementById condition, then the browser will run the next line. If it does not, then it will move to the next condition specified in the function.

Line 8:We create a variable called endPos (signifies end position of animation) and point it to document.getElementById(id).offsetLeft; statement. The offsetLeft method is a way of determining the current elements position from left of screen. If we wanted to capture the elements position from top of screen then we would use offsetTop. This method works on IE5+, Safari, Mozilla based browsers and Opera 7+.

Line 9:Closing bracket for condition.

Line 10:Specifies our second condition. Because Netscape 4 uses a completely different method of capturing an elements current position, we need to specify a condition for that browser by using the document.layers object.

Line 11:If the browser is Netscape 4, then the endPos variable will call the document.layers[id].left; statement.

Line 12 & 13:Closing brackets for the function.

Just to be clear on what we are doing in the above function. Conceptually, that element who's current position we are capturing is an active element. This allows us to define an end point for the animation, in other words where the animation will end up on a mouseover event. Now that we have captured an elements end position, we can move on to the main animation function.

Pages: firstback1 3 4 forwardlast

Similar/related articles:


 
  Sponsors