[英]How can I animate this image in a td using jQuery and/or css?
<td id="display5" class="displayableCell" style="border: 0px none; width: 120px;">
<span id="name5">Photo Name</span>
<br>
<img id="img5" height="auto" width="120px" src="/Home/GetPhoto/53">
</td>
I have tried many things to no avail. 我尝试过很多东西都无济于事。 This is my most recent attempt, which minimizes the image, but does not move it to the right which is the whole goal here.
这是我最近的尝试,它最小化了图像,但没有将它向右移动,这是整个目标。 How to animate it to the right, outside of the td area.
如何在td区域外向右边设置动画。
var target = "#img" + Displayable.count;
$(target).animate({ "left": "+=240px", "width": "-=120px" }, "fast");
取而代之的是动画left
属性,您可以使用相同的结果修改margin-left
,但是您没有更改position
属性,但图像应该是正确的动画。
$(target).animate({ "margin-left": "+=240px", "width": "-=120px" }, "fast");
In order to animate the left
property, you'll want to add position: absolute
to your image. 要为
left
属性设置动画,您需要为图像添加position: absolute
。 That's likely why it wasn't moving to the right. 这可能就是它没有向右移动的原因。
Most likely you are not setting a position
CSS property for the img
elements. 很可能你没有为
img
元素设置position
CSS属性。 By default the position
property for an element is set to static
which makes the element ignore top
/ left
/ right
/ bottom
property declarations. 默认情况下,元素的
position
属性设置为static
,这使得元素忽略top
/ left
/ right
/ bottom
属性声明。 You need to set the element's position
to something other than static
. 您需要将元素的
position
设置为static
以外的其他position
。
Since you want the image to animate out of it's parent container, I suggest using position : absolute
: 既然你想让图像从它的父容器中动画出来,我建议使用
position : absolute
:
.displayableCell > img{
position : absolute;
top : 20px;
left : 0;
}
That's all you need to change, the jQuery code you provided works fine. 这就是你需要改变的全部,你提供的jQuery代码工作得很好。
Here is a demo: http://jsfiddle.net/PYsjz/ (click the image to see the animation) 这是一个演示: http : //jsfiddle.net/PYsjz/ (点击图片查看动画)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.