Hello! I've created a sliding image viewer here. As you can see, there's 4 small clickable images to change/slide the image. I want the small image to change to this image when it's clicked, or when the appropriate main image is showing. That way the users can tell which main image is being shown. Can anyone maybe look at the source and explain how to do this? Thanks!
+5
A:
Hello, try the following code !!
var src = [];
src['normal'] = "http://beta.d-load.org/images/etc/imagev-norm.png";
src['active'] = "http://beta.d-load.org/images/etc/imagev-over.png";
$(document).ready(function() {
$('a',$('.paging')).click(function() {
$('a',$('.paging')).find('img').attr('src',src['normal']);
$(this).find('img').attr('src',src['active']) ;
});
});
Here you go, Demo : http://jsfiddle.net/qTB9g/
Ninja Dude
2010-07-19 17:20:04
Only thing is that he wants to use an image, so you'll either have to set it as the background image for that class or actually change the selected image's source.
ryanulit
2010-07-19 17:41:34
`@ryanulit` now, I understand what exactly he wants. Thanks for letting me know
Ninja Dude
2010-07-19 17:52:37
Thanks! Although I couldn't get it to work with a background image. Any way to change an image's source from CSS?
Joey Morani
2010-07-19 17:52:45
hey, I just updated the code check out http://jsfiddle.net/NfjMB/
Ninja Dude
2010-07-19 18:03:54
Thanks, I'll give it a go. :)
Joey Morani
2010-07-19 18:11:21
you're welcome :) Have a Nice Day !!
Ninja Dude
2010-07-19 18:14:16
No problem. That code should work fine.
ryanulit
2010-07-19 18:49:22
Thanks again. Just one last question now:- What do I do if there's other images on the same page which have been hyperlinked? The code seems to replace them images with the 'normal' or 'active' images. Is there a way to use something else other than "$('a').find('img')", as from my understanding (which is very little); that's looking for all images which are hyperlinks.
Joey Morani
2010-07-19 20:30:28
@Joey Updated !!!
Ninja Dude
2010-07-19 20:44:04
Thanks!! Works great. You've helped me a lot. :)
Joey Morani
2010-07-19 21:02:49