Aaron Boodman's ypSimpleScroll script modified by www.zigotica.com
Example one
Javascript is a different layer of the style and structure ones, and like CSS, it should
not be required but optional, so that without its use the page should be accessible and usable.
If the browser cannot interpret the code it will not execute it, but the contents will be
accessible. This is generally called script degradation. Now, being more specific, what makes
a piece of code unobtrusive?
- Mix with structure: mainly, script behaviour not being mixed with
page contents. This means there will be no intrinsec events inside the document and
the file will be stored in a separate .js file.
- Initialization: the ideal solution is the script being initialized
automatically on page load
- Assign actions with an event handler: because we have avoided the
use of intrinsec events we will need a way to associate actions (execute functions) to
events captured by different elements on the page.
- Compatibility: browsers that dont understand the code must do without
it throwing no error messages.
- Capacities detection: to allow the previous point be true we will use
object detection instead of browser detection.
Ending example one.
Example two
Table of Contents from titles (TOC)
This script reads all nodes in a document and stores the titles hierarchic structure
in a variable, showing them in an indented list according to their order. Sections of the
list are links to the real section on the page, using the id of the titles (script creates
them if needed).
Form validator
This script reads all text fields of a form making all "required" classes
having to be filled before sent to server, otherwise warning visually and through an alert.
If the field is named email it forces (with a regular expression) to use a
valid email.
Ending example two.
TextScrollWith.zip( 8 k)