Mentalhead
Mentalhead

Reputation: 1505

scale() CSS3 property moves other elements on hover

I'm trying to make a gallery, however, I'm having a problem with scale property. It appears that if I hover quickly over several elements they start to move about 1px back and forth due to scale().

HTML:

    <section id="first">
                        <section>
                             <img src="http://tympanus.net/Tutorials/OriginalHoverEffects/images/1.jpg" />  
                            <a href="#">
                                <div class="shade">

                <h5>Cappuccino</h5>
                                <p>
                                    This is Photoshop's version  of Lorem Ipsum. Proin gravida nibh vel velit auctor aliquet.
                                </p>
                            </div>
                            </a>
                        </section>
                        <section>
                             <img src="http://tympanus.net/Tutorials/OriginalHoverEffects/images/1.jpg" />  
                            <a href="#">
                                <div class="shade">
                                <h5>Cappuccino</h5>
                                <p>
                                    This is Photoshop's version  of Lorem Ipsum. Proin gravida nibh vel velit auctor aliquet.
                                </p>
                            </div>
                            </a>
                        </section>
                        <section>
                             <img src="http://tympanus.net/Tutorials/OriginalHoverEffects/images/1.jpg" />  
                            <a href="#">
                                <div class="shade">
                                <h5>Cappuccino</h5>
                                <p>
                                    This is Photoshop's version  of Lorem Ipsum. Proin gravida nibh vel velit auctor aliquet.
                                </p>
                            </div>
                            </a>
                        </section>
                        <section>
                             <img src="http://tympanus.net/Tutorials/OriginalHoverEffects/images/1.jpg" />  
                            <a href="#">
                                <div class="shade">
                                <h5>Cappuccino</h5>
                                <p>
                                    This is Photoshop's version  of Lorem Ipsum. Proin gravida nibh vel velit auctor aliquet.
                                </p>
                            </div>
                            </a>
                        </section>
                        <section>
                             <img src="http://tympanus.net/Tutorials/OriginalHoverEffects/images/1.jpg" />  
                            <a href="#">
                                <div class="shade">
                                <h5>Cappuccino</h5>
                                <p>
                                    This is Photoshop's version  of Lorem Ipsum. Proin gravida nibh vel velit auctor aliquet.
                                </p>
                            </div>
                            </a>
                        </section>
                        <section>
                             <img src="http://tympanus.net/Tutorials/OriginalHoverEffects/images/1.jpg" />  
                            <a href="#">
                                <div class="shade">
                                <h5>Cappuccino</h5>
                                <p>
                                    This is Photoshop's version  of Lorem Ipsum. Proin gravida nibh vel velit auctor aliquet.
                                </p>
                            </div>
                            </a>
                        </section>

CSS:

#first img, .shade{
    margin-left:0.5%;
    margin-bottom:0.5%;
}
#first>section{
    position:relative;
    float:left;
    margin: 0.7% 0.7% 0 0;
    overflow:hidden;
    width:273px;
    height:182px;
}
#first>section img{
    position:relative;
    -webkit-transition: all 0.2s linear;
}
#first>section>img:hover{
     -webkit-transition: all 0.2s linear;
}
.shade:hover{
    opacity:1;
}
.shade{
    width: 253px;
    height: 162px;
    background:rgba(255, 144, 0, 0.65);
    position:absolute;/* needed*/
    top:0;/* needed*/
    left:0;/* needed*/
    opacity:0;
    color:#fff;
    padding:10px;
    -webkit-transition: all 0.2s ease-in-out;
}
.shade p{
    margin-top:60px;
    width: 255px;
}
.shade h5{
    text-decoration:underline;
    font-size:110%;

jQuery:

$(window).load(function(){


picLink=$("#first a");
picLink.mouseover(function(){
$(this).prev().css("-webkit-transform","scale(1.3)");
});
picLink.mouseout(function(){
$(this).prev().css("-webkit-transform","scale(1.0)");
});

});

Here's a live example: http://jsfiddle.net/VJWg6/1/

Upvotes: 2

Views: 2803

Answers (1)

Mateusz Kocz
Mateusz Kocz

Reputation: 4602

I assume that by "going back and forth" you mean this slightly disturbing effect of images covering that small, 1px wide space on their left-side.

It happens because you have a margin-left property specified on them (#first img). This margin keeps space inside the overflow:hidden container (section), so when images are resized they simply cover this space.

As a solution you could just remove the margin-left on images and move it to the section (of course you will need to adjust the percentage, since the context changes.).

This small fix: http://jsfiddle.net/VJWg6/23/

Upvotes: 2

Related Questions