如何在图库中平滑过渡缩放图像?

时间:2012-08-06 04:13:55

标签: jquery css

我想创建一个缩放效果类似于this one的图库。当鼠标悬停在图像上时,它将显示带有一些额外标记的较大版本的图像。

标记:

<div class="gallery">
    <div class="gallery-item">
        <img src="image.png" width="150" alt="" />
        <div class="gallery-item-full">
            <img src="image.png" width="250" alt="" />
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit</p>
        </div>
    </div>
    .
    .
    .
</div>

CSS:

.gallery {
    margin: 100px auto;
    width: 600px;
}

.gallery-item {
    float: left;
    position: relative;
    margin: 0 25px;
    width: 150px;
}

.gallery-item-full {
    z-index: 999;
    position: absolute;
    background: #fff;
    border: #ccc 1px solid;
    padding: 5px;
    top: -50px;
    left: -50px;
    opacity: 0;
}

.gallery-item:hover .gallery-item-full {
    opacity: 1;
}

这很有效,但我希望像previous gallery一样平稳过渡。我愿意使用Javascript / jQuery。

感谢。

1 个答案:

答案 0 :(得分:4)

试试这个:http://jsfiddle.net/FPKAP/12/(有点不同,但我最近为某人做了)

希望它符合您的需求:)

link:Enlarging images when mouseover using Jquery?

<强>码

$('#zoomimg').mouseenter(function() {
    $(this).css("cursor","pointer");
    $(this).animate({width: "50%", height: "50%"}, 'slow');
});

$('#zoomimg').mouseleave(function() {   
    $(this).animate({width: "28%"}, 'slow');
});

<强>码

$('#zoomimg').hover(function() {
    $(this).css("cursor", "pointer").animate({
        width: "50%",
        height: "50%"
    }, 'slow');

}, function() {
    $(this).animate({
        width: "28%"
    }, 'slow');

});​
相关问题