Banner/Ad Rotation Script?

netsavy006

Seasoned Veteran
Joined
Apr 18, 2007
Messages
2,705
Reaction score
7
FP$
579
I would like to offer my forum members the option of submitting an ad (similar to the buysellads format you have here). But for this ad rotation, the user would submit a banner with a link as to where it should take the person when clicked.

What I am in need of is a script that could handle this.

Thanks,
~ Andy
 
Code:
<script type="text/javascript">
var images = [], 
index = 0;

images[0] = "<a href = 'http://imperian.co.uk/'><img src='http://i.imgur.com/TxQVzpc.png' alt='Imperian'></a>";
images[1] = "<a href = 'http://passica.com/index.php'><img src='http://i.imgur.com/P2qIrhM.png'></a>";
images[2] = "<a href = 'http://flatfreebies.com/'><img src='http://piic.us/di/AV6R/424343443.png'></a>";
images[3] = "<a href = 'http://pixelbanter.com/'><img src='http://pixelbanter.com/misc/adverts/468x60.png'></a>";

index = Math.floor(Math.random() * images.length);
document.write(images[index]);
//done
</script>
Exact copy of the code in use on Forum Hour. It's public code though. 🙂
 
A jQuery one i just made.

http://jsfiddle.net/xensoft/uBVS6/

HTML:
Code:
<a href="#" id="banner"><img src="default.png" alt="" title="" /></a>

Javascript:
Code:
var banners = [{
    url: 'http://forumpromotion.net/viewtopic.php?f=84&t=107410',
    image: 'http://oi41.tinypic.com/35a3t03.jpg'
}, {
    url: 'http://www.fmsupport.net/',
    image: 'http://i.imgur.com/fwnbKkj.png'
}, {
    url: 'http://tegdesigns.com/',
    image: 'http://i.imgur.com/sCyrIhS.png'
}];

var index = 0;

var rotate = function () {
    $('#banner').attr('href', banners[index].url);
    $('#banner img').fadeOut().attr('src', banners[index].image).fadeIn();

    index = index + 1 == banners.length ? 0 : ++index;
};

rotate();

setInterval(rotate, 3000);

Feel free to use it if you wish. 🙂
 
Back
Top Bottom