Hope this basic example helps:
HTML Code:
<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>
Bookmarks