I’m trying to create a gallery, but being totally new to jQuery I’m in a kind of deadlock.
I want to create a gallery consisting of several small pictures that expand to full width on click and return to its original on another. At the same time I want all the rest divs in parent wrap to hide while clicked image expands. All that must be running smoothly and prettily. That’s what I can’t reach.
All pics have .image class and each of them has class .one .two and so on. They are all under parent wrap.
$(".image").bind('click', function() {
$(this).animate({width: "100%", height: "100%"}, 800);
$(".image").not(this).hide("slow");
});
$('.image').toggle(function(){
$(this).animate({width: "100%", height: "100%"}, 800);
}, function(){
$(this).animate({width: "90px", height: "90px"}, 800);
$(".image").not(this).show("slow");
});
The result of my efforts by now http://jsfiddle.net/baltar/TRuNv/4/
Good example of smoothness here http://css-tricks.com/examples/InfoGrid/
Also, it would be great to set up adjusting the height of parent div on the fly, so image of any proportions will fit. I’ve tried to set parent’s height to auto, but that didn’t work.
I realize that my question is to big to ask, but maybe at least anyone could advise which direction should I look to.
Thanks in advance!
The following jQuery does most of what you request:
This requires the CSS:
JS Fiddle demo.
References:
addClass().animate().click().clone().fadeOut().height().offset().parent().position().siblings().width().