jQuery-动画,向左而不是向右扩展/调整大小 [英] Jquery - animate, expand/resize to the left rather than to the right
问题描述
所以我有要在鼠标悬停时放大的图像,所以我有类似的东西.
so I have this image that I want to magnify on mouseover, so I have something like this.
$('#something').animate({
width: bigger-than-now,
height: bigger-than-now
});
但是我发现当我希望它向左下扩展时,它总是向右下扩展?有谁知道我怎么能做到这一点?提前致谢!
but I found that this always expand toward bottom-right, when I want it to expand toward bottom-left? does anyone know how I can accomplish this? thanks in advance!
即好吧,我确实发现,如果我将css位置设置为绝对位置,并且将top,right = 0设置为左下角.但是我想在我的情况下相对定位.
i.e. Well, I do find that it would do bottom-left if i set the css position to absolute, and top, right=0. but then I would like relative positioning in my case.
推荐答案
如果您不想使用绝对位置,则可以为图像提供较大的初始填充,然后按照您希望图像的方向减少该填充扩展.
If you don't want to use position absolute, you could give the image a large initial padding and then reduce that padding in the direction you want the image to expand.
CSS
#something {
height: 100px;
width: 100px;
padding-top: 10px;
padding-left: 10px;
}
jQuery的顶部和左侧分别增加了10px
$('#something').animate({
width: 110,
height: 110,
paddingTop: 0,
paddingLeft 0
});
这篇关于jQuery-动画,向左而不是向右扩展/调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!