![](/img/trans.png)
[英]How can I animate two jquery lazy line painter animations one after the other?
[英]How can I execute two different jQuery animations right after each other with the same “button”?
當我按下按鈕時,我動畫我的.header_inner
向下移動。 但是當我再次按下按鈕或向上移動動畫時,如何讓它回到原來的位置?
碼:
<script>
$('.handler').click(function(){
$('.header_inner').animate({
top:"-=-28%",
}, 300);
});
</script>
當我再次按下按鈕時,我希望我的.header_inner
再次回到.header_inner
。
您可以創建一個布爾變量,指示最后一次移動是向上還是向下:
var upwards = false,
newTop;
$('.handler').click(function(){
if (upwards) newTop = '28';
else newTop = '-28';
$('.header_inner').animate({
top:"-=" + newTop + "%",
}, 300);
upwards = !upwards;
});
相同但沒有全局變量:
function toggleAnimate(){
$('.header_inner').animate({
top:"-=" + ((toggleAnimate.upwards)? '28':'-28') + "%",
}, 300);
toggleAnimate.upwards = !toggleAnimate.upwards;
}
toggleAnimate.upwards = false;
$('.handler').click(toggleAnimate);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.