Learn free online HTML5, javascript, and jquery Tutorials by Examples

Saturday, 13 December 2014

Image change with refresh or load a page by javascript

<SCRIPT LANGUAGE="JavaScript">
var imgs = new Array()

      imgs[0] = 'html-css-js2.jpg'
      imgs[1] = 'css3_html5_and_jquery_wallpaper_by_vien84-d68ls5i.jpg'
      imgs[2] = 'css3_html5_and_jquery_wallpaper_by_vien84-d68ls5i.png'
      imgs[3] = 'Gallery Page Exhibitions.jpg'
      imgs[4] = '2014 - 1.jpg'
     
var j = 0
var p = imgs.length;
var preBuffer = new Array()

for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = imgs[i]
}
var whichImage = Math.round(Math.random()*(p-1));

function showImage(){
if(whichImage==0){
document.write('<a href ="#"><img src="'+imgs[whichImage]+'" border=0 width=452 height=181></a>');
}
else if(whichImage==1){
document.write('<a href ="#"><img src="'+imgs[whichImage]+'" border=0 width=452 height=181></a>');
}
else if(whichImage==2){
document.write('<a href ="#"><img src="'+imgs[whichImage]+'" border=0 width=452 height=181></a>');
}
else if(whichImage==3){
document.write('<a href ="#"><img src="'+imgs[whichImage]+'" border=0 width=452 height=181></a>');
}
else if(whichImage==4){
document.write('<a href ="#"><img src="'+imgs[whichImage]+'" border=0 width=452 height=181></a>');
}


}
showImage();
</script>
<div>
     Image here
</div>

No comments:

Post a Comment