Wednesday,
10th Mar 2010
Rotating Stamp Images

[javascript]

Rotating Banner Script


The above rotating banner is very easy to achieve. It can even be used with images of differing sizes, but looks more professional if the images are kept to the same size.

First, cut and paste the following script in-between the <head> and </head> tags of your page:

I like to keep all my banner images in a directory called 'banners' - this helps to keep my sites organised and it makes it easier to find and change graphics if I need to. I make all my banners the same size and then upload them to my banners directory..

If you look at the code above, you will see the first part of the script has the comment //specify banners. Below that you will see a list of banner images - each one represented by a number in the script. There are two lines to each image:.

banpics[0] = new Image();
banpics[0].src = "http://www.daxassist.com/banners/rotban1.gif";

0 is allocated to the first image. The second image is given the number 1 and the code looks like this:

banpics[1] = new Image();
banpics[1].src = "http://www.daxassist.com/banners/rotban2.gif";

You can have as many banners as you wish but each one must have it's own two lines of code as above and it's own unique number following in sequence to the banner preceding them.

You also need to put the full URL to the location of the image. If you are using images from another site or server, you need to point to the directory that the image is stored in. Often, when sharing banners, people allow you to link to the banner on their site to save your own bandwidth. If this is the case, they should give you the full URL to where their banner is located on their server.

The second part of the script has the comment //specify banners links.. This is where you put the link URL to each respective banner. The link must have the same number [0] or [1] as it's image counterpart. It must also be the full URL - even if it is linking to another page on your own site.

You can adjust the speed that the banners rotate by altering the delay variable at the beginning of the script. It is currently set to 2000. If you increase the number, the banners rotate slower and decreasing the number will cause the banners to rotate quicker.

There is another variable just below the delay variable called newbrowser. When set to true;, any link activated by the banners will open in a new browser. If you want the pages to open in the same browser, change this variable to false;.

Then add the following line to your body tag to initiate the rotation when the page loads:
<body onload="bannerchanger('banner');">

Finally, in your page, you add an image tag at the point you want the banners to display with an anchor tag around it something like this:

<a href="javascript:FollowLink();"><img id="banner" name="banner" src="http://www.daxassist.com/banners/rotban1.gif" border=0></a>

Use the first banner image of your rotation to start the ball rolling. If you don't want your rotating banners to be links, simply remove the anchor from around the banner image tag and they will then become simple rotating images.

And that's all there is to it!