简体   繁体   中英

Enlarge image on hover and add spotlight text

I am having difficulty finding a tutorial on enlarging an image on mouse hover, then shading the enlarged image dark so I can put some text over it.

This example does almost everything except make the image larger: http://jsfiddle.net/balupton/FZG3v/

CSS:

.ih { position:relative; }
.ih, .ih-image, .ih-info { display:block;width:330px;height:220px; }
.ih-image, .ih-info { z-index:500;position:absolute;top:0;left:0;right:0;bottom:0; }
.ih-info { z-index:501;background:black;color:white; }

HTML:

<img class="ih-image" src="http://designsnack.com/screenshots/image.php width=330&amp;height=220&amp;cropratio=330:220&amp;image=/screenshots/8264948088.jpg"/>
     <div class="ih-info">
         Your overlay content
     </div>
</div>

JS:

$(function(){
$('.ih').hover(
    // Over
    function(){
        var $ih = $(this);
        $ih.find('.ih-info').stop(true,true).animate({opacity:0.8}, 400);
    },
    // Out
    function(){
        var $ih = $(this);
        $ih.find('.ih-info').stop(true,true).animate({opacity:0}, 400);
    }
).find('.ih-info').css('opacity',0);
});

It's my first question, apologies if I am not clear or am missing some information.

Many thanks for any help!

EDIT: Thanks ghost! My end goal is to enlarge the image from the center as ultimately there will be 4 images in a 4X2 configuration.

您可以使用jQuery以多种方式执行此操作,其中之一是使用animate()方法平滑地更改图像大小: http//jsfiddle.net/FZG3v/44/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM