我想實現的:當兄弟被刪除時,如何讓HTML div動畫變得平滑過渡?
我正在處理我的頁面上的CSS/JS動畫。
小提琴=>https://jsfiddle.net/hngz8rq4/
的HTML
<div class="container">
<div class="mock-requests">
<div class="mock-request">
<div class="mock-request-inner">
</div>
<small>Box 1</small>
</div>
<div class="mock-request">
<div class="mock-request-inner">
</div>
<small>Box 2</small>
</div>
<div class="mock-request">
<div class="mock-request-inner">
</div>
<small>Box 3</small>
</div>
<div class="mock-request">
<div class="mock-request-inner">
</div>
<small>Box 4</small>
</div>
<div class="mock-request">
<div class="mock-request-inner">
</div>
<small>Box 5</small>
</div>
</div>
</div>
的JS
var mockRequests;
mockRequests = (function() {
var animationStep0, animationStep1, animationStep2, callNextStep, init, itemHeight, startTimer, step, timeDelay, timer;
timer = null;
step = 0;
timeDelay = 1600;
itemHeight = 0;
init = function() {
if (document.querySelector('.mock-request')) {
$(".mock-request").addClass('animated');
itemHeight = $('.mock-request:first').css('height');
return startTimer();
}
};
startTimer = function() {
return timer = setInterval(callNextStep, timeDelay);
};
animationStep0 = function() {
$('.mock-request:first').addClass('checked');
return step += 1;
};
animationStep1 = function() {
$('.mock-request:first').addClass('zoomOutLeft');
return step += 1;
};
animationStep2 = function() {
console.log("Setting item height: " + itemHeight);
$('.mock-request.checked').removeClass('checked zoomOutLeft').remove().css({
"height": itemHeight
}).appendTo('.mock-requests').addClass('zoomInBottom');
return step = 0;
};
callNextStep = function() {
return eval("animationStep" + step + "()");
};
return {
init: init
};
})();
$(document).on("turbolinks:load", mockRequests.init);
的CSS
@charset "UTF-8";
body {
font-size: 16px;
color: white;
}
small {
position: absolute;
top: 1.8rem;
left: 1rem;
font-size: 0.5rem;
}
.mock-request {
position: relative;
height: 3rem;
border-color: white;
border-width: 3px;
border-style: solid;
border-radius: 4px;
width: 100%;
max-width: 320px;
margin: 1rem auto;
}
.mock-request:before {
position: absolute;
top: 0.6rem;
right: 1rem;
font-size: 1.2rem;
color: white;
font-family: "FontAwesome";
content: "\f10c";
}
.mock-request.checked:before {
content: "\f058";
}
.mock-request-inner {
position: absolute;
top: 1rem;
left: 1rem;
height: 0;
width: 80%;
border-color: white;
border-width: 3px;
border-style: solid;
border-radius: 4px;
}
.container {
background-color: black;
}
我想重新創建的效果類似於iOS上的滑動刪除效果。我希望它看起來像堆棧中的元素正在被檢查,然後向左滑動以擺脫它。
一旦物品被移除,堆棧應該優雅地向上滑動以代替先前的第一項。
該序列應該連續循環。
爲了提高效率,我從堆疊中取出第一件物品,並將其重新附加到堆疊的底部。
問題:
目前,有一次我從棧中刪除頂部的元素,他們的休息跳起來拿前面兄弟的地方。我希望這種過渡發生緩慢(〜0.8s),而不是立即發生,因爲現在正在進行。
有人可以建議一個優雅的方式來完成這個序列?
謝謝!