13.02.2013 Views

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

WEB STANDARDS CREATIVITY

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

252<br />

Adding sliding behaviors<br />

Now that we have used scripting to toggle between the exposed and the normal position for each of the navigation panes,<br />

we can add in scripting that slides the navigation out from “under” the main navigation. We accomplish this by changing the<br />

height of the pane to 0 when the exposed state is activated and writing a function that reveals the navigational pane by<br />

changing its height.<br />

As an alternative, when we activate the exposed state, we could put an appropriate padding-top on the<br />

content div to allow the navigational pane to sit on top of the content. Using a negative value for the CSS<br />

top property, we could hide the navigational pane under the navigation at the top and use JavaScript to slide<br />

the div#inner-wrap down the appropriate distance. However, during early testing of this solution, some<br />

testers reported a “choppy” sliding behavior. This was, in part, due to sliding a div that essentially contained<br />

all the content on the page. As the size of the page grew, the sliding just wasn’t smooth.<br />

Both this solution and the one used in the example require additional scripting, but neither have significant<br />

impact on accessibility from a technical perspective. (Although there may or may not be issues with sliding<br />

navigation in general, for people with cognitive disabilities, for example.)<br />

The finished script includes several additional features that make it work well:<br />

Simple error-checking to prevent the user from clicking twice on a tab. Once a navigational pane is “moving,” the<br />

function simply returns rather than calling it again.<br />

A basic reset function that can be used to reset the tabs to their original state.<br />

A constant SLIDEINTERVAL, which lets us define the speed at which the Reveal function will be called repeatedly. In<br />

this case, we call it every 65 milliseconds.<br />

We could take an extensive tour through this script, looking at the changes that we’ve made in a step-by-step manner. For<br />

example, we could look in detail at the animation strategy. However, I want to focus specifically on the accessibility side of<br />

things in detail and leave most of the core script to speak for itself. You’ll find comments throughout the script to detail<br />

what is happening. Here is the listing for the final core script, wscslide.js:<br />

var slideready = false;<br />

var SLIDEINTERVAL = 65;<br />

var revealTimer = null;<br />

var moving = false;<br />

window.onload = function() {<br />

slideready = true;<br />

}<br />

function toggle(element) {<br />

if (!slideready || moving) return false;<br />

reset(element);<br />

if (!document.getElementById) return true;<br />

var elt = document.getElementById(element);<br />

var initialheight= elt.offsetHeight;<br />

Reveal(element, initialheight);<br />

//return false;<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!