GVA Grimly Image 1
Edinburgh Libraries 1
GVA Grimly Image 2
Edinburgh Libraries 2
Buchanan Galleries 1
7th
2009

jQuery Image Gallery

Posted by Jamie Connolly
jQuery Image Gallery Preview

A while back I was helping out a co-worker doing some work that required the use of an HTML/Javascript image gallery. He provided me with a jQuery Image gallery from this webpage. The original gallery allows multiple images with the option to start a slideshow.

The work that was being done required an auto start function and the ability to add links to the images. The original gallery was very easy to use and to adapt so I decided to use it and just and in the extra functionality that we needed. To see the final gallery we used (before going with a Flash solution) ina action follow the link below:

jQuery Image Gallery

Download the full scripts and test here.

I had to do some reconstruction of the original javascript file, but it has been appropriately commented making it easy for you to change it as you see fit. If you have any problems with the code do let me know and I will look into it, or even any recommendation for additional functionality.

Thanks to the original author of the software.

Jamie


28 Comments in “jQuery Image Gallery”

On July 9th, 2009 at 4:52 pm
Christoph H. said:

Thanks for this great plugin!

I have one problem:
The gallery always appears in the top left corner, not where I placed the UL-Tag. How can I position it correctly?

Regards!

Hi Christoph,

The original gallery (<ul class=”gallery”></ul>) is actually replaced by the div tag (<div id=”img-gallery”></div>) with the appropriate UL tags inside.

So the CSS must match the ID #img-gallery. The format of the output HTML is as follows:


Hope this helps

Jamie

On July 10th, 2009 at 7:37 am
Christoph H. said:

Thanks for your help, but it didn’t fix my problem.

I want to put the .gallery in a certain DIV and position it within my layout. But the Gallery is always shown in the left top corner of the browser / BODY.

For testing you can put “…” around your UL.gallery in your jqueryTest.html. The Gallery will be positioned above the DIV.

Thanks for your help.

Hi Christoph,

Good Spot, Yes the gallery will automatically be populated in the BODY tag. I have uploaded a new version to include a ‘target’ ID on the javascript making it easy to place.

If you just want a quickfix you can amend the following line the javascript file (jquery.gallery.js, line 52):

$('body').prepend(galleryStructure);

Change the ‘body’ part to the name of your div. Remember to include the ID(#) or Class(.) identifiers as well.

Hope that solves the problem, you can download the new files from the same link as before if you want the new javascript file that includes the ‘target’ attribute including a the format of the output HTML that the javascript creates.

Thanks for your comments

Jamie

Hi,

Its really a great plugin, well I have a requirement to start autoplay on load and when clicking on the number the respective image would come and then after few seconds the gallery would start playing automatically from the next image.

Hi Sabhajit

Thanks for your comment. In order to have the gallery restart automatically you can add the following line to the jquery.gallery.js file just under line 91 as shown here

// ###################################################
// IF LINK IS CLICKED (NOT PLAY/STOP)
// ###################################################
$('#img-gallery ul a:not(#playstop)').click(function(){

	var imgToLoad = $(this).attr('href'); // GET LINK HREF
	imgToLoad = imgToLoad.split('#'); // SPLIT HREF TO GET IMAGE NUMBER
	imgToLoad = parseInt(imgToLoad[1].substr(3)) - 1; // RETRIEVE IMAGE NUMBER
	changeImage(imgToLoad); // CHANGE THE IMAGE TO THE SPECIFIED NUMBER
	currentImage = imgToLoad + 1; // SETUP SLIDESHOW FOR NEXT IMAGE

	if(slideShowActive == true) $('#img-gallery ul a#playstop').click(); // TRIES TO STOP SLIDESHOW WHEN PRESSED

	setTimeout(function(){$('#img-gallery ul a#playstop').click();},5000);
	return false;
})
NOTE: The the timeout function uses milliseconds.

You can set the time by changing the ‘5000′ value to your own number.

Hope this helps

Jamie

Hey Jamie - nice work… However, thought I should point out that it fails when served up under an XHTML 1.0 Strict (served as xml, with an XML prologue) doctype?

Hi Ceri,

Thanks for the reply, yes the CSS link tag was missing the close tag character (/), the gallery itself appears to pass with no problems. I have updated the zip file to remove this error. Thanks for pointing it out.

Jamie

hi Jamie, that’s really helpful. i have one question, how to use div instead of img, because i used multi-images in several divs, and would like to display a div each time

Hi Andy

The current javascript file doesnt really support full div sections, it would take some reworking to do it. Its a good idea for improvement so if you check back in a couple of days (maybe a week) I will create a brand new javascript file that would support it.

Jamie

Hi jamie

thats great, look forward to seeing your new version shortly.

Thanks for getting the auto-play working, this is exactly the slideshow I was looking for and it took an amazing amount of time for me to find it.

On September 9th, 2009 at 5:02 pm
Francesco said:

Thank you for sharing!

I had to comment out the numbered list because I have 50+ images and it overflowed vertically :)

// ADD IN LINKS
	$(img).each(function(i){
	$('#img-gallery ul').append('<a href="#img' + (i + 1) + '" rel="nofollow">' + (i + 1) + '</a>');
	})

The good addition of this plugin to the original version is also the “target” option, very useful. It would even better in the case if not specified, it would replace the original ID used to hold the supplied list of images, instead of spawning just after the BODY tag, that is a ugly behaviour that would almost never be used.

Regards and keep up the good work!

Thanks much for this informational entry.

Hi Francesco

There is functionality in the HTML java call that disables the Image List if set to false, did you try it?

As for the target option, yes this is a good idea for improvement in the next version.

Thanks for your input

Jamie

On September 17th, 2009 at 7:50 am
Francesco said:

Oops, no I didn’t notice the option to disable the list! Thank you

This is such a great gallery script. However, on the initial page load, it loads all the images under eachother and sometimes one on top of eachother, and where a caption isn’t specified, it states ‘undefined’. Hitting refresh sorts it all out, but not all visitors to the site will know to do that. I thought it was something I had copied over incorrectly, but then noticed that the same happens on your test page. Is there any way of rectifying this at all?

Hi Vicky

I am aware of the issue, I’m still trying to work out why it happens, problem is I can’t reproduce the problem on my website.

I use the script on my homepage and get round the problem because all my images are the same size.

If you can restrict the image size to a specifc height like I have on my homepage you can do the following to get round it until I figure it out

If you set the CSS for the outlining div to the following

.[your-div]{
         height: specific height;
         overflow:hidden;
}

I am creating a flash equivalent to the image gallery so have a look back soon if that could help (no loading problems in flash)

Hope that helps

Jamie

Hi Jamie

Many thanks for your response. I think that’s the best answer, so I’ll work on making all the imagery the same height. If you want to see the problem in action, you can see it on a page I have uploaded here:
http://www.inhouseoxford.co.uk/kitchen_renovation_project3.php

Personally, I love the fact that this is an effective gallery which doesn’t use flash.

Many thanks again for a great script.

All the best
Vicky

I see the problem on your page, I will have a look at the code and try to change it in a way that stops this from happening

Cheers
Jamie

On November 6th, 2009 at 5:47 pm
Anthony Jones said:

For some reason I can’t open the links into a new browser window. The html is structured as so:

<img src=”/images/t4.jpg” border=”0″ alt = ” title=”Example Text” longdesc = “Example TextLearn more >>” />

Any help would be appreciated,
Anthony

Hi Anthony, if you require the links to open in a new window you must open the jquery.gallery.js file andnavigate to the following line (line 34):

var galleryStructure = '


';

Here you can insert the attribute target=”_blank” into the hyperlink tag as shown below:

var galleryStructure = '


';

Hope thats what your looking for

Jamie

On November 10th, 2009 at 10:00 pm
Jason Todd said:

I’ve got a few user complaints that doing a CTRL-F5 refresh in Firefox 3.5 screws the pooch on the gallery layout. I was mildly relieved that it happens on the demo here and it’s not a conflict with the rest of my page, but was wondering if you were aware of it or were working on a fix?

Cheers,
Jason

Hi Jason

Yes I know theres a loading problem where the images go right down the page. I’m still looking into the problem, but a workaround I used on my homepage was to give a specified height to the surrounding div and to set the css to overflow:hidden. Of course this will only help when your gallery is always the same height.

Hope that helps for the moment.

Jamie

On December 9th, 2009 at 7:40 am
Deny Aryanto said:

on IE7&8 somehow even overflow: hidden added, still images list vertically shown, and the transition not as smooth as FF. Is there any other way to get trough IE? btw it’s really a nice plugins…really, not like others, thank you

Hi Deny,

Have you applied a static height to the div in question? I know there are a few issues on IE with various items (microsoft keep moving the goal posts) I am going to build a brand new version from scratch and take in all the requests and bring it out sometime in the early new year. In the meantime have you tried display:block options in the CSS. If you send me a link to your page I could take a quick look at it?

Cheers

Jamie

Hi,

First of all I must say a VERY BIG thank to you for sharing such a wonderful piece of code. I have been looking for this for weeks.

I have got one problem with IE though. In some IE browsers (not all) when the page loads all images are shown vertically and they all flashing. This doesn’t happen in FF though. I think this is the same issue that Aryanto is having.

Thanks again for the code and very much appreciate your help to resolve this.

Cheers,

Manoj

Heya
Great photo gallery, perfect for what i needed but…
I know Jason mentioned this problem already but i wanted to add that even after I put in a fixed height div and with hidden overflow it keeps the page at the right height but the auto motion gets jammed on one image. Had a really tight look but can’t seem to fix it. It is ok after a couple of refreshes which makes me think its a timing/loading problem. Anyway only seems to be a firefox issue for me…


Leave a Reply

Search website

Search

Blog Categories

Designers

 

« back to blog home