Reputation: 1539
I am having a bunch of photos and I'm looking for best way of displaying them at the same place using jQuery.
What do you think of my concept? Is it valid or maybe there are other ways than putting all images on each other and playing with opacity?
Anyways I don't know why this code:
jQuery('#demo img .'+itemClass).animate({opacity: 1});
Doesn't show a thing. Any helping hand?
Upvotes: 3
Views: 251
Reputation: 1987
You have typo(no space) between img and itemClass. it should looks like this :
jQuery('#navi a').click(function(){
var itemClass = jQuery(this).attr('class');
$('#demo img').animate({opacity:0});
jQuery('#demo img.'+itemClass).animate({opacity: 1});
//alert(itemClass);
});
Upvotes: 1
Reputation: 19709
Ok this is what I did for it to work:
jQuery('#demo img .'+itemClass)
to jQuery('#demo img.'+itemClass)
Upvotes: 2
Reputation: 20602
Right a few problems.
Updated: http://jsfiddle.net/d4sEW/7/
.attr('class')
- this is wrong, there is no attribute class, it's .attr('className')
img
and the class, otherwise it looks for a class as a descendant of the image, not a part of it: $('img.class')
Upvotes: 1
Reputation: 91734
I´m pretty sure class names can´t start with a number, but even so, if your image has a certain class, you have to use img.'+itemClass
instead of img .'+itemClass
; you put a space between the img selector and the class.
Apart from that you will have to remove / fade-out the images that you don´t want to show as otherwise one image can show behind an image you don´t want to show.
Upvotes: 3