2

我正在尝试制作一个画廊,但是,我遇到了规模属性的问题。看来,如果我快速将鼠标悬停在几个元素上,它们会由于 scale() 而开始前后移动约 1px。

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)");
});

});

这是一个活生生的例子:http: //jsfiddle.net/VJWg6/1/

4

1 回答 1

2

我假设“来回走动”是指图像覆盖了左侧 1 像素宽的小空间的这种稍微令人不安的效果。

发生这种情况是因为您margin-left在它们上指定了一个属性 ( #first img)。此边距在overflow:hidden容器 ( section) 内保留空间,因此当调整图像大小时,它们只会覆盖该空间。

作为一种解决方案,您可以删除margin-left图像并将其移动到section(当然,您需要调整百分比,因为上下文会发生变化。)。

这个小修复:http: //jsfiddle.net/VJWg6/23/

于 2013-02-22T19:03:13.163 回答