1. Home
  2. Computing & Technology
  3. JavaScript

Vertical Scroller

3. Add to Your Page

clr gif
Join the Discussion

Questions? Comments?

More of this Feature

Introduction Obtain the Script

What remains to be done in setting up our vertical scrollers is to position the scrollers on your web page with the appropriate size and appearance. This part of the setup is done by placing a div on the page where we want a scroller to appear. We set the id of the div to the same name as we used in the first parameter of the startScroll function call that we want to process the scroller and use stylesheet commands to define the size and appearance.

The first scroll box on my sample page is defined using the following div code in the body of the page where the scroller is to appear.

<div id="myscroller"></div>

The size and appearance of that scroll box is defined using the following stylesheet commands.

#myscroller {
position:relative; // mandatory
width:200px; height:150px; // set as required
background-color:#ffffcc; // set as required
overflow:hidden; // mandatory
border:solid 1px; margin:5px; // optional
}

The stylesheet commands can either be enclosed within <style></style> tags in the head of your page or included in an external stylesheet linked to your page. The position and overflow attributes must be specified exactly as shown. The width, height, and background-color attributes must be included but you can choose for yourself how big the scroll box will be and what colour. I included the border and margin attributes to tidy up the appearance of this scroll box. The second sample scroller does not include these attributes.

I used the following to link it into my sample page as an external stylesheet so that the scroller only appears on the screen in version 5+ browsers:

<link rel="stylesheet" href="scroller.css" type="text/css" media="screen" />
Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.