views:

26

answers:

2

I'm using galleriffic to handle my image gallery and I'm having a problem with the thumbnail active states.

Galleriffic doesn't have support for active states on the images - only the list items. Right now the gallery will assign a "selected" class to the current LI containing the thumbnail and I've been trying to use jQuery to target the thumbnail ID within the active LI so I assign an active state to the image and then return it to the default state.

Essentially I'm doing:

$('.selected img#myImage').attr('src', 'path_to_active_state.jpg');

Which works, however, I can't get the image to go back to the default afterward. I don't think there's jQuery support for using hasClass in an if statement, but if someone knows please help out. Any advice is welcomed.

A: 

Could you try the :not selector? You're currently doing this to get the selected image:

$('.selected img#myImage').attr('src', 'path_to_active_state.jpg');

Try doing this to get the unselected image:

$(':not(.selected) img#myImage').attr('src', 'path_to_active_state.jpg');
Matt Huggins
A: 

You could add a class to the active image, so that you can identify it later..

so

$('.selected img#myImage').attr('src', 'path_to_active_state.jpg').addClass('altered');

and when highlighting another thumbnail

$('.altered').attr('src', 'path_to_inactive_state.jpg').removeClass('altered');

also in your example $('.selected img#myImage') seems to imply that you use the same id for all thumbnails (#myImage). Id's should be unique inside the DOM..

Gaby
Yea, I assigned unique IDs to all of the images so I could target them differently. I was hoping to write something that would get the original source, store it in a variable, assign the new source of the active image and then return it to the original source when another thumbnail was selected. Thanks for your response.
Patrick
@Patrick, you need to create a logic behind the active/non-active paths to the thumbnails.. so that you can make them active/non-active without knowing the original or altered state..(for example a **some-image.jpg** for the normal and **some-image-active.jpg** for the active, and manipulate the src to add/remove this suffix). In my code i show you how to add a class to the active one so you can find it later and return it to the non-active image..
Gaby