可以使用 jquery 为特定的高度和宽度设置动画,同时保持顶部和左侧不变吗?
Can use jquery animate to specific height and width while keeping the top and left as constant?
$(div).animate({
height:"40px",
width:"40px",
top:"0px",
left:"0px"
}); // In this case i want the top and left to be set at 0px.
但是 div 正在缩小到不同的位置
我的 div 当前位于顶部位置:50px 和 left:50 像素,高度为 100px,宽度为 100 px.I 想将其移动到顶部 0px 和左侧 0px 并使其高度40px 和宽度 40px
首先确保你设置 left:"0px"
这样,""
秒。它应该工作。请参阅下面的代码段:
也许您还有一些其他代码在干扰
$("div").animate({ height:"40px", width:"40px", top:"0px", left:'0px' });
div {
height:100px;
width:100px;
position:relative;
top:0;
left:0;
background:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
</div>
$(div).animate({
height:"40px",
width:"40px",
top:"0px",
left:"0px"
}); // In this case i want the top and left to be set at 0px.
但是 div 正在缩小到不同的位置
我的 div 当前位于顶部位置:50px 和 left:50 像素,高度为 100px,宽度为 100 px.I 想将其移动到顶部 0px 和左侧 0px 并使其高度40px 和宽度 40px
首先确保你设置 left:"0px"
这样,""
秒。它应该工作。请参阅下面的代码段:
也许您还有一些其他代码在干扰
$("div").animate({ height:"40px", width:"40px", top:"0px", left:'0px' });
div {
height:100px;
width:100px;
position:relative;
top:0;
left:0;
background:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
</div>