Background image slideshow javascript source code

Here is the code for background image slideshow using javascript and css.

check out the code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us">
<style>
body{
background-repeat: no-repeat;
background-position: 50 50;
}
</style>
<script >
//Specify background images to slide
var imgs=new Array()
imgs[0]="img1.jpg";
imgs[1]="img2.jpg";
imgs[2]="img3.jpg";
//Specify interval between slide (in miliseconds)
var speed=2000
//preload images
var processed=new Array()
for (i=0;i<imgs.length;i++){
processed[i]=new Image();
processed[i].src=imgs[i];
}
var inc=-1;
function slideimg(){
if (inc<imgs.length-1)
inc++;
else
inc=0;
document.body.background=processed[inc].src;
}
if (document.all||document.getElementById)
window.onload=new Function('setInterval("slideimg()",speed)');
</script>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="table1" height="381">
	<tr>
		<td>
			<p>This is just dummy text</p>
			<p>This is just dummy text</p>
			<p>This is just dummy text</p>
			<p>This is just dummy text</p>
		</td>
	</tr>
</table>
</body>
</html>

You can use it for any elements background.

hope it will be useful.
thanx n regards,
Nikhil Ughade
Web Designer
[Pune]

About these ads

About Nikhil
Name : Nikhil Ughade UI Developer, Accidentally in design field, no turn back since then. Location : Pune (MH, INDIA) From : Amravati (MH,INDIA) College : VYWS's College Of Engg. Badnera, Amravati Hobby : Social Networking, Designing Web Sites, Photography, Reading Books. In Free time works for NGO.

4 Responses to Background image slideshow javascript source code

  1. vidandroide says:

    It is exactly (almost) what I was looking for, buy … Is it possible to fade in images?

  2. Hi Nikhil,
    I like this script but I have a question. How to put it into a specific DIV ?

    Example: I have a DIV called “header_clearfix” where I would place differnt images as background, rotating every X seconds.

    Can you help me ?

    NOTE: I cannot use Jquery in my site, so I would like to use your script.

    Thanks
    Sandro

  3. Contact me using Twitter @realsandrotoni

    Thanks

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 260 other followers

%d bloggers like this: