开发者

set the image's origin with css on hover

开发者 https://www.devze.com 2023-03-02 00:43 出处:网络
i want to enlarge an image on hover with css. but w开发者_JS百科hen it grows, it grows from the top-left. how can i make it grow from the center? Unless I\'m missing something obvious, I think you\'ll

i want to enlarge an image on hover with css. but w开发者_JS百科hen it grows, it grows from the top-left. how can i make it grow from the center?


Unless I'm missing something obvious, I think you'll have to manually offset the img on :hover:

See: http://jsfiddle.net/QwvRk/

img {
    position: relative
}
img:hover {
    width: 150px;
    height: 150px;
    top: -25px;
    left: -25px
}


You need to animate the size and placement at the same time. As far as i know, the only way to do that is with an absolutely positioned item. So if you are using jQuery it would be:

$('#selector').animate({
top: -=20px,
height: += 20px,
width: += 20px}, 250);
0

精彩评论

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

关注公众号