views:

47

answers:

2

Hello All,

I have a list of images. When the page load each time I want to show the next image in the series, and when it reloads again I want to change next image, etc.

Please suggest me a solution using jQuery.

Thanks

+2  A: 

I suggest you use the plugin cycle. It's as easy like that:

$('.slideshow').cycle({
        fx: 'fade'
    });

http://jquery.malsup.com/cycle/

Or if you want a carrousel: jcarousel

http://sorgalla.com/jcarousel/

netadictos
@netadictos: my issue is i want to change images one by one when page load
Mubeen
@Mubeen - I think you need to clarify the question. Do you mean "each time a page loads I want to show the next image in a series" - so I visit several pages and see "image1.png" on the first page, then on whatever page I visit next I see "image2.png" and so on...
Sohnee
@Sohnee: yes when page load each time i want to show the next image in series in the same page
Mubeen
+3  A: 

You should consider using server side technology to do this. However, this can be accomplished easily enough with jQuery, or even library-less Javascript.

Using cookies, we can store the current image count, which can then be used to access an array of image URL which is used to change the image on page load. Using the cookie script from QuirksMode, we have a script that looks like this:

var images = ['img1.png', 'img2.png', 'img3.png', 'img4.png' ...],
    imageCount = parseInt(readCookie('image'), 10);

if(isNaN(imageCount)) imageCount = 0;

$('#thumbnail').attr('src', images[imageCount % images.length]);
createCookie('image', imageCount + 1, 30);

If you're using vanilla Javascript, replace the 6th line with this:

document.getElementById('thumbnail').src = images[imageCount % images.length];

See a demo of this script here: http://www.jsfiddle.net/yijiang/2cqqt/

Yi Jiang
thanx its working. I accept ur answer
Mubeen