views:

41

answers:

2

I've been fighting with jQuery all night and getting quite frustrated here, so forgive me if the answer was staring me in the face.

I have a 5x3 grid of 15 images contained within a <div>, and when I click on one of them, I want it to expand to three times its original size of 150x105 and overlap the rest. I've got the expanding down, but the overlapping isn't quite working.

My current HTML:

    <div id="image-grid">
        <img src="images/after-pictures/1.jpg" class="igc1" />
        <img src="images/after-pictures/2.jpg" class="igc2" />
        <img src="images/after-pictures/3.jpg" class="igc3" />
        <img src="images/after-pictures/4.jpg" class="igc4" />
        <img src="images/after-pictures/5.jpg" class="igc5" />
        <img src="images/after-pictures/6.jpg" class="igc1" />
        <img src="images/after-pictures/7.jpg" class="igc2" />
        <img src="images/after-pictures/8.jpg" class="igc3" />
        <img src="images/after-pictures/9.jpg" class="igc4" />
        <img src="images/after-pictures/10.jpg" class="igc5" />
        <img src="images/after-pictures/11.jpg" class="igc1" />
        <img src="images/after-pictures/12.jpg" class="igc2" />
        <img src="images/after-pictures/13.jpg" class="igc3" />
        <img src="images/after-pictures/14.jpg" class="igc4" />
        <img src="images/after-pictures/15.jpg" class="igc5" />
    </div>

The igc* class denotes the column the image is in.

CSS:

#image-grid {
    border: 1px solid #aaa;
    width: 745px;
    padding: 5px 2px 2px 5px;
}

#image-grid img {
    width: 150px;
    height: 105px;
    margin: -2px;
}

jQuery:

$('#image-grid img').click(function() {
    $(this).animate({
        width: '450px',
        height: '315px',
        zIndex: '10'
    }, 200);
});
A: 

It could be that you're trying to apply a z-index to elements which have not been given the position absolute property also?

Danjah
you don't really have to go absolute... relative is just fine... and besides, absolute positioning gives lots of trouble if your purpose was just really the z-index...
Reigel
The images not being affected by jQuery don't have a set positioning. I tried adding a z-index to them; didn't help, so I deleted it, and it still didn't work. I don't want to do absolute, because then I'd have to go through and set pixel values for each image, and that sort of defeats my goal of simplicity.
soren121
Sorry, yeah, I should've been broader in my statement - you may need to just apply positioning in general, so the t/r/b/l values take hold. So as Reigel mentions, apply position:relative to the images beforehand.Or find a fix like you did above!! :P
Danjah
A: 

somewhat like this...

$('#image-grid img').click(function () {
    $(this).animate({
        width: '450px',
        height: '315px'
    }, 200)
    .css({
        'z-index': function (i, z) {
            return z + 10;
        }, position: 'absolute',
        left: 0,
        top: 0
    })
    .siblings().css({
        'z-index': function (i, z) {
            return z - 10;
        }, position: 'static',
        width: '150px',
        height: '105px',
        left: 'auto',
        top: 'auto'
    });
});​

let me know what's the effect..

Reigel
That code does nothing in Firefox and Chrome, I'm afraid. Though you do know that the `img` tag has no siblings, right?
soren121
I don't know what's not working for you, but here's a demo... http://jsfiddle.net/mMuYF/2/ and given by your html structure, img tags has lots of img tags as it's siblings...
Reigel
Oh, I was confusing siblings with children. Oops.
soren121
OK, it appears to be working now...not sure what was wrong before. It'll need some tweaking, but I'm pretty sure I can do that on my own. Thanks! :)
soren121
okay cool!... get it dude!.. cheers!
Reigel