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?
Ending example one.
As you'll see next, I also modified it so the page could handle more than one scroller, even with different sizes, as that was another requirement for that website. So I created a function that added a counter to an array and we pass as arguments the index of that instance and the size for that scroller. The script just does the rest.
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).
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.
I think it's quite easy to implement, you need:
<link rel="stylesheet" type="text/css" href="scroller.css">
<script type="text/javascript" src="dom-drag.js"></script> <script type="text/javascript" src="ypSimpleScrollC.js"></script> <script type="text/javascript" src="scroller.js"></script>
instantiateScroller
as follows:
<script type="text/javascript"> instantiateScroller(0, "scroll0", 7, 0, 300, 150, 150); </script>The argument values refer to:
<div class="root" id="root0"> <div class="scrollContainer" id="scroll0Container"> <div class="scrollContent" id="scroll0Content"> All content will go inside here </div> </div> </div>
Once you accomplish these the script will do the rest for you. You can download the script with all the needed files in raw format from here