我有3个按钮居中在一个容器。 当用户点击其中一个按钮应该去容器的左上角。其他按钮应该消失。动画从中心向左与jquery
我成功做到了,但是我不能让按钮从原始位置开始动画,这是因为我在开始动画之前将按钮位置更改为绝对位置。
我认为正确的做法是从开始给按钮的绝对位置,但我不知道是否有可能(页面应该是响应)。
这里是我的HTML:
<body>
<div id="inner_body" style="position:relative;margin: auto;text-align: center;width:50%;margin-top: 200px">
<button class="bc" id="0" style="margin-top: 400px;margin-left:20px;margin-right:20px;padding: 20px;background-color: #718bf3">Botton A</button>
<button class="bc" id="1" style="margin-top: 400px;margin-left:20px;margin-right:20px;padding: 20px;background-color: #718bf3">Botton B</button>
<button class="bc" id="2" style="margin-top: 400px;margin-left:20px;margin-right:20px;padding: 20px;background-color: #718bf3">Botton C</button>
</div>
</body>
和jQuery脚本:
$(document).on('click', '.bc', function() {
$('#' + this.id + '').css({
position: 'absolute'
}).animate({
left: 0,
marginTop: 0
}, "slow");
for (var i = 0; i < 3; i = i + 1) {
if (i != this.id) {
$('#' + i + '').delay(1200).fadeOut(300);
}
}
});
的'inner_body'有固定'height'? –
不可以。内体高度是动态的。单击按钮后将填充更多文字。 – Andy