View Full Version : How to create a randomly selected banner?
CardinalX
09-20-2008, 10:59 AM
I´ve started a forum at invisionfree.com and would like to have a randomly selected image displayed at the top of the page each time you load/reload the page. I´ve tried using various online tutorials without success, and now I´ve been recommended to use this place. So could you write the code I need to use, and leave a "blank" in the areas I need to fill in with image locations? I´m a computer iliterate, so I need things spelled out for me. Thanks in advance.
rangana
09-20-2008, 01:56 PM
Hope this basic example helps:
<style type="text/css">
.myimage{width:400px;height:300px;}
</style>
<script type="text/javascript">
/*
* Title: Random Image Script
* Code by Raymond Angana. username: rangana [dynamicdrive.com/forums]
* This notice must remain intact
*/
var rPics=[
'http://rangana.moonylist.com/images/Picture7.jpg',
'http://rangana.moonylist.com/images/Picture2.jpg',
'http://rangana.moonylist.com/images/Picture3.jpg',
'http://rangana.moonylist.com/images/Picture4.jpg' // note that the last element in the array dont have comma
]; // Add all the picture variables in this array.
window.onload=function() {
rRandom=Math.floor(Math.random()*rPics.length); // Randomly choose a number
var img=document.createElement('img'); // Create an image element
img.setAttribute('src',rPics[rRandom]); // Set the source of the image
img.className='myimage'; // Set a class name for the image. This is use to style the image via CSS
document.getElementById('header').appendChild(img); // Append the image
}
</script>
<div id="header">
<h1>Banner Here</h1>
</div>
CardinalX
09-20-2008, 03:55 PM
Well, the image shows now, but underneath the preceding banner (there´s already a banner on the site which will be a regular image displayed), is there a way to have the randomly selected image show next to the banner? And the images that get randomly selected get stretched/shrinked, is there a way to remove the automatic resizing?
CardinalX
09-20-2008, 04:03 PM
And as long as I´m being difficult; the banner and image are displayed against a background made up of horizontal blue stripes which I really don´t like, is there a way to make the background area all white?
tjmorgan
09-22-2008, 01:28 AM
Openx is free software for displaying ads. You will need access to mysql to create a database. After you get the program installed displaying ads will be simple....... No more messing with scripts. It will work to rotate or display images, ads, html blocks, flash. Goolge it you will like what you see!
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.