jQuery Image Change - Gallery View
NickName:Brad Birdsall Ask DateTime:2009-08-12T21:15:25

jQuery Image Change - Gallery View

I have a large image in a gallery that needs to change when one of the thumbnails is clicked within a unordered list below. The images are coming in dynamically so the jquery script needs to be able to take the src of the thumbnail, remove "-thumb" from the filename, and then replace the large image with the new source.

Please let me know what is my best approach to a gallery like this.

Thanks in advance.

-B

Copyright Notice:Content Author:「Brad Birdsall」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/1266098/jquery-image-change-gallery-view

Answers
karim79 2009-08-12T13:23:19

Something like:\n\n$('img.thumb').click(function() {\n var src = $(this).attr('src');\n $('#bigImage').attr('src', src.replace(/-thumb/,''));\n});\n\n\nThe below examples apply if your thumbs are being loaded in via ajax:\n\n(1) Using Events/live:\n\n$('img.thumb').live(\"click\", function() {\n var src = $(this).attr('src');\n $('#bigImage').attr('src', src.replace(/-thumb/,''));\n});\n\n\n(2) As a callback to one of jQuery's ajax methods (e.g.):\n\nfunction initThumbs()\n{\n $('img.thumb').click(function() {\n var src = $(this).attr('src');\n $('#bigImage').attr('src', src.replace(/-thumb/,''));\n });\n}\n\n$('#thumbsDiv').load('thumbs.php?p=2', initThumbs);\n",


James Wiseman 2009-08-12T13:36:15

karim79's answer could be shortened slightly:\n\n$('img.thumb').click(function() {\n $('#bigImage').attr('src', $(this).attr('src').replace(/-thumb/,''));\n});\n\n\nBut otherwise, good answer!",


Juicy Scripter 2009-08-12T14:00:09

The only addition to karim79's is:\n\nIn a case the thumbnails are placed within same parent binding an event on that parent would be much better (elegant?) solution that binding events on all thumbnails. The event is propagated, so you can find thumbnails by checking event target.",


More about “jQuery Image Change - Gallery View” related questions

jQuery Image Change - Gallery View

I have a large image in a gallery that needs to change when one of the thumbnails is clicked within a unordered list below. The images are coming in dynamically so the jquery script needs to be abl...

Show Detail

Change image in gallery

I have a gallery where I'm displaying a number of ID cards as images. When the user clicks on an image, I want to change the image to another one which shows the 'back' of the card. I have bound an

Show Detail

Jquery Image Gallery with categories

I am going to use the Galleriffic jquery plugin to display my images (please look at demo here: http://www.twospy.com/galleriffic/advanced.html I want to include categories above the gallery, but ...

Show Detail

How to select dynamic image from Gallery View in JQuery

Hello all I am newbie on jQuery and i am working on one application, I need to select an image from Galary View in JQuery. I tried doing this code. // I need to set image dynamically so i am tak...

Show Detail

Changing image angle in android gallery view

i want my gallery application to be modified , like coverflow. but not exactly like coverflow. the images in the gallery view should be viewed in such a way that it should look like reverse letter ...

Show Detail

JQuery image gallery on JSP

Right now I have a small media portal project (Servlet API/JSP) on which you can upload and view images. Now I want to add some kind of JQuery image gallery plugin into my project for viewing image...

Show Detail

jQuery Image Gallery with jCarousel with changing preview

I found this script: http://www.queness.com/post/3036/create-a-custom-jquery-image-gallery-with-jcarousel which has everything I need except one thing. On right side selection is changing but prev...

Show Detail

Gallery lag when change image

I try to use gallery to show image in network. But when turn left or right to change image. The image shows delay about 3 seconds to load from network each time. May it load next image in backgroun...

Show Detail

how to change gallery view?

Hi I have created one gallery project. but I wish to created folders view gallery..I dont know how to create that kind of gallery...please post some sample full coding... This is my current galler...

Show Detail

jQuery gallery - load image and then animate

is there any possibility how to load an image with jQuery in background and than animate the transition? I have a gallery of big fullscreen images as a background for my website. I have paths of all

Show Detail