开发者

jquery image resize transition onMouseOver

just wondering if there is any jquery plugin that when your mouse is over an ima开发者_如何学Pythonge, this image will increase in size and if your mouse is out of the image it'll decrease in size all this as a smooth transition. thanks!


You could try the Zoomer gallery plugin, or roll your own based on this tutorial. Personally I would go the tutorial route since it'll give you more control over the result (and you'll learn something to boot ;)


If you just want one image you can use jQuery's UI effects. Note this is separate from the base jQuery - add this below your call of jQuery.

<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>

Now that you've added a link to the UI we can use its effect library like so:

script:

$(document).ready(function() {
    $('#imgid').hover(function(){$(this).effect("scale",{percent:200},500)}, function(){$(this).effect("scale",{percent:50},500)})
});

html:

<img id="imgid" src="path/to/img.png" alt="(Vacation Slide)">

Just remember that when you scale something up you need to figure out how to scale back down since the new size will be 100%. In my code we double it (200%), then reduce it by half (50%) to get back to the original. Feel free to play with the transition time, and any callbacks you might need to get it perfect.

Link to the jQuery .hover() and to jQuery UI effects


There is a jQuery hack:

$(document).ready(function() {
    $('#target_selector').mouseover(function(){
        $(this).css('height':'value', 'width':'value')
        $(this).mouseout(function(){
            $('this').css('height':'value', 'width':'value')
        });
    });
});

But you could use a CSS pseudo-class, :hover

#target_selector {
    height: value;
    width: value;
}
#target_selector:hover {
    height: value;
    width: value;
}

Either could be applied to this sample HTML

<html>

<body>

    <img id="target_selector" />

</body>

</html>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜