Javascript Image Slideshow

Image Slideshow With Fading Transition

A common practice for many website's is to have a rotating graphic as part of their intro or home page. You know the one with all the happy, smiling faces and sunshine. Anyway, this script is a good alternative to a flash slideshow for your site that offers fading transitions and is cross-browser compatible. While it is more flexible as far as which and how many images you use, it is a bit more processor intensive than a flash movie would be.

I've changed the code a bit from the original version to trim it down and to keep it from displaying all the images in a non JavaScript enabled browser. Now it will only show the initial pic if Java is nixed. The original script remains pretty much intact. The original article can be found here.

Surprised by this great code snippet Use this code when flash is not an option Spicy image transition indeed Basking in the glory of this great design technique Can you see the advantages this script might offer? Playing with JavaScript is fun

The HTML

Here is the html used in this solution. Note that the style is added directly to the first image thus overriding the css below which initially hides the images inside the container. This way a user with javascript disabled will still see the initial image but of course not the additional images.

 
<div style="position:relative; ">
	<div id="imageContainer">
		<img style="display: block; opacity: 0.95;" 
		src="images/x1.jpg" />
		<img src="images/x2.jpg" />
		<img src="images/x3.jpg" />
		<img src="images/x4.jpg" />
		<img src="images/x5.jpg" />
		<img src="images/x6.jpg" />
	</div>
</div>

The CSS

Here is the css used in this example. Of course you will need to set the height and width for your solution. Also note that in the html above the imageContainer is set in a relatively positioned div to allow the absolutely positioned images to display correctly.

 
#imageContainer { height:309px; }  
#imageContainer img { display:none; 	
			position:absolute; 	
			top:0px; left:0px; 	
			height:309px;  	
			width:500px; 	
			opacity: -0.01; } 	

The JavaScript

Here is a link to the js file being used for this page. Use the interval variable, set at interval=5000 for this example, to set the desired time between new images.

Thanks!

Just wanted to say thanks for the slideshow code, I've replaced the Flash slideshow in my photo website because I was never happy that it didn't work with iPhone. Thanks again! Elliot.

Object orientated version

Object orientated version complements igaro.com. Allows multiple slideshows with diff interval. Enjoy :) #contresimgprev img { display:none; position:absolute; top:0px; left:0px; opacity: -0.01; } function imgslide(obj) { this.imgs = new Array(); this.current=0; this.interval=obj.interval; this.id=obj.id var self = this; this.init = function() { this.imgs = document.getElementById(this.id).getElementsByTagName("img"); for(var i=1;i.99) { obj.xOpacity = .99; return; } obj.style.opacity = obj.xOpacity; obj.style.MozOpacity = obj.xOpacity; obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")"; } }; }; content_read_resources_images_overview = new imgslide({ id:'contresimgprev', interval:2000 }); content_read_resources_images_overview.init();

Multiple slideshows

Thanks for the great work! Is this possible to use multiple slideshows in a single page?

Thanks

Great script, just when I needed it, thank you so much.

Delayed Start up

I have finally found a script that works on the site's banner area. However, how can I make the rotation start sooner than it does? Also, I had to list the images backwards in order for the 1st image I wanted to show first to show. Any suggestions on what I need to change? Thanks!

RE: Delayed startup

Can you post a link to an example of where you are experiencing this? If you are using rather large image...it may increase the time it takes for the images to actually start rotating

Good codes. Thanks!

Good codes. Thanks!

Hey can anyone offer me any

Hey can anyone offer me any help on how I would go about centering this on a webpage? I've tried a couple different methods but nothing seems to work...thanks

Place the slideshow in a

Place the slideshow in a container with a fixed width and apply the style margin:0 auto have a link where you are trying to achieve this?

Great!!!

Thanks a lot for sharing such wonderful script.... thanks

nice one, thanks:)

nice one, thanks:)

Helpful script. but needed a

Helpful script. but needed a play pause button with this

Great code, cross browser compaeible

Hi, is there any way i can make the transition of the images still slow, and run the script whenever the page loads.

Adding Text Descriptions

Thanks for sharing! just wondering how you would add in a text description for each image?

Here is the html used in

Here is the html used in this solution. Note that the style is added directly to the first image thus overriding the css below which initially hides the images inside the container. This way a user with javascript disabled will still see the initial image but of course not the additional images. Ваша Фраза

many thanks

Great once you know how! thanks for fixing the hate between javascript and I

Thank you!

This is great! Thank you for all of your hard work!

Random?

Hey guys... great script. Anyway this script can pull the images at random?

Works nice, except the

Works nice, except the slideshow overlaps my left-side navigation pop-out submenus. Is there any way to set a z-index or something to get this slideshow to not interfere with the navigation? My menu is CSS powered. Thx

xfade

Brilliant ! thankyou so much for sharing this code!

Thanks

It was meant to demonstrate the capabilities of Ajax as a SDK and to show that with a few lines of code most of the capabilities that once were only offered by commercial softwares can be easily recreated.

good

good

good

good

Sweet!

Sweet!

More than 1 group of images

Nice script. I like that it's SEO frinedly. Is there any way to have mopre than 1 set of images on a page?

Great script!

Great script!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

Verify Your Humanity
This question is for testing whether you are a human visitor and to prevent automated spam submissions.