SUBSCRIBE - [ Tech News ] [ Make Money Blogging Tips ] [ Online Marketing Tips ] [ Web Dev News ]
Powered by MaxBlogPress  

Building a Javascript Ad Rotator / Slideshow (with 123 buttons, play, pause and stop options)

August 22, 2008 by MK  
Filed under CSS, Javascript

This script work in all major browsers - IE6, IE7, Firefox 3.0. You can even rotate images and flash objects as everything within DIV’s will be rotating.

Example of Banner Rotation using this script -

These are real banners rotating using this script. You can click on 1 2 3 buttons to see a particular banner or play / pause the rotation. Banners sequence will change randomly everytime you refresh the page

The idea is to pick up all the DIV’s within the main DIV container and rotate them randomly.

Here is an example of the Ad Rotator / Slideshow with some CSS thrown in and play/pause, 123 buttons. Please feel free to use the CSS and code. Leaving the reference back to my site (http://www.coolwebdeveloper.com) in the comments will be much appreciated though.

We will be using a set of open source scripts in addition to my own code to build this javascript adrotator/slideshow.

Please scroll to the bottom of the article to download the zipped files package that we are going to use for this project.

You will find a number of methods inside slideshow.js to control the slideshow. At the top level is a javascript class used to initiate the slideshow object from the HTML file.

Some of the options that can be set are -

duration - sets the total duration of transitioning per image
seconds_per_slide - sets the time per image/div is shown
pause_on_mouseover - whether the rotation will be paused when mouse over happens
onChange: function() {} - You can define here, any javascript code that you want to run when the image changes

Following functions are used to control the behavior of the slide show -

forward()
backward()
jumpToSlide()
start()
pausePlay()
stop()
rndm()
transition()

Class can be initiated by using following code - You can pass any available number of property values when defining the rotation class

var slideshow = new MDSK.Slideshow(”slideMainDiv”, “.slideDiv”, {
seconds_per_slide: 5.0
});

The random() function is used to change the rotation pattern every tine the page is refreshed, as a result the images contained within the object are displayed randomly.

/**********************************/

rndm : function(min, max){
return Math.floor(Math.random() * (max - min + 1) + min);
},

/**********************************/

and then we will call this function every time the class object is instantiated

/**********************************/

this.slides.sort(function(a,b){
return me.rndm(-1,1);
});

/**********************************/

Please fill in the following information to receive the Javascript Adrotator code with fully working example via email and to subscribe to FREE Newsletter and email feed.
Your email address will also be used to provide any important updates and new versions for Adrotator script in near future.

All the scripts are pretty self explanatory but if you have any questions please dont hesitate to contact me by leaving a message in the comments section.

There is a lot of room for improvement in this code and lot of inline CSS can be moved to CSS file. Also, I am working on a wordpress adrotator plugin (enhancing this code) and will be releasing soon. So keep checking this site.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis
  • Yahoo! Buzz

Related posts brought to you by Yet Another Related Posts Plugin.

Comments

59 Responses to “Building a Javascript Ad Rotator / Slideshow (with 123 buttons, play, pause and stop options)”
  1. This is just what i needed. Lovely. Thanks a lot for share.

    Don

  2. Tfudge says:

    I am having a problem in IE. I have 3 images in the rotation.
    When the second image loads it has an error with the page and the rotation stops.

    Any idea why?

  3. eMoney Blog says:

    Hello!
    This script is great! I have been trying to figure out how to integrate it with wordpress but I just can’t.
    I read on your post you were working on a wordpress plugin? How is that going?
    Is it ready yet?
    I am really looking forward to it!
    So far I haven’t been able to find a wordpress plugin that displays ads on javascript, only after page refresh.
    Anyway, I will be checking back on your site!
    Great work!
    Cheers

  4. MK says:

    yup, Plugin has been ready for a while now and have been getting great reviews. You can visit this page for more info -
    http://coolwebdeveloper.com/plugins/

  5. Craig says:

    Nice script, but I am finding that the ‘backward()’ function is not working. Any ideas?

  6. Vince says:

    This is a great rotator…working great on my site. However I would like it to have the ability to degrade when a user has scripting disabled in their browser by showing one of the three images in its place, prferably randomly with each refresh or loading of the page. Right now it just shows white space with the pause/play/1-2-3 controls.

    Does anybody know what code I can use to do this?

  7. Vince says:

    How can I make this script degrade gracefully when the viewer have javascript disabled in their browser? I woul like to be able to show one of the banners in its place.

  8. Mircea says:

    It’s working. It’s great. Thanks. You help me finishing my page.

Trackbacks

Check out what others are saying about this post...
  1. [...] was using Dynamic JavaScript Ad Rotator Slideshow script with my WordPress BLOG and WordPress theme I am using uses jQuery. I was getting “null” [...]



Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!