Home arrow HTML arrow Page 3 - How to Create a Dynamic HTML Navigation Page
HTML

How to Create a Dynamic HTML Navigation Page


Learn how to devote an entire page to an image-driven, DHTML navigation system. This code from Dan Wellman will result in a fully functioning, interactive navigation page that loads a new page whenever a specified location of the window is passed over by the central image.

Author Info:
By: Dan Wellman
Rating: 4 stars4 stars4 stars4 stars4 stars / 59
September 07, 2004
TABLE OF CONTENTS:
  1. · How to Create a Dynamic HTML Navigation Page
  2. · Web Animation Doesn't Always Mean Flash
  3. · Subroutines
  4. · The Remaining Subroutines
  5. · Wrap'n it Up
  6. · Images to Use

print this article
SEARCH DEVARTICLES

How to Create a Dynamic HTML Navigation Page - Subroutines
(Page 3 of 6 )

Surprisingly, you need to write a total of thirteen subroutines to make it happen: eight onclick events (two for each directional button), plus five additional sub's to control the image movement. There are four global variables that are used throughout the script to control the image animation. They need to be global because each of them is accessed by two separate subroutines, so they need to be declared at the start of the script:

dim leftButtonDown
dim upbuttonDown
dim rightButtonDown
dim downButtonDown
dim animator

The first four are switches that are set to either 1 or 0 and are 'switched' by various mouse events. The reason you need four of them is that the script seems to get a little confused if you use just one, and the movement of the central image is a little irrational. Try using just one switch and see what happens.

Next you need to script the onclick events, two for each of the directional control buttons:

sub buttonLeft_onMouseDown
 animator=window.setInterval("flyLeft", 10)
 leftButtonDown=1
End sub
sub buttonLeft_onMouseUp
 window.clearInterval(animator)
 leftButtonDown=0
end sub

The mouseDown event initiates the setInterval method, which take a subroutine name and an integer as its argument, and assigns this to a variable, in this case 'animator'. The setInterval method is used to repeat a subroutine for a specified number of milliseconds, so what we're telling the script to do is execute the flyLeft function repeatedly for 10 milliseconds. It is this that produces the smooth animated movement of the central image, as you'll see when the file is finished. The subroutine also sets the leftButtonDown switch to on. We could simply call the subroutine that moves the central image instead of using the animator, but this way, users of your site would need to repeatedly click the directional button to move the image. 

The mouseUp event uses the clearInterval method to stop the animation and takes simply the variable name assigned to setInterval as an argument. It also switches leftButtonDown back off. Without the mouseUp subroutine, the central image you continue to move after the user had stopped clicking.

In using these two subroutines you'll find that the images scrolls across the screen while the directional button is down, and stops as soon as the button is released. After writing the remaining OnClick subroutines, you should end up with a block of code like this:

sub buttonLeft_onMouseDown
  animator=window.setInterval("flyLeft", 10)
  leftButtonDown=1
 End sub
 sub buttonLeft_onMouseUp
  window.clearInterval(animator)
  leftButtonDown=0
 end sub
 sub buttonUp_onMouseDown
  animator=window.setInterval("flyUp", 10)
  upButtonDown=1
 End sub
 sub buttonUp_onMouseUp
  window.clearInterval(animator)
  upButtonDown=0
 end sub
 sub buttonRight_onMouseDown
  animator=window.setInterval("flyRight", 10)
  rightButtonDown=1
 End sub
 sub buttonRight_onMouseUp
  window.clearInterval(animator)
  rightButtonDown=0
 end sub
 sub buttonDown_onMouseDown
  animator=window.setInterval("flyDown", 10)
  downButtonDown=1
 End sub
 sub buttonDown_onMouseUp
  window.clearInterval(animator)
  downButtonDown=0
 end sub


blog comments powered by Disqus
HTML ARTICLES

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials