最初にクリックされたアイテムやボタンがクリックされた順序に関係なく、要素を上から下にアニメートできますか?jqueryで要素と位置をソートする方法
たとえば、(下)のような出力が、スニペットの入り口のアニメーションとクロージング機能を維持します。
Fourth
Second
First
Third
jQueryの(FIDDLE):
$(document).ready(function() {
//ENTRANCE
$("#first").css("top", -1000);
$("#1st").on('click', function() {
setTimeout(function() {
$("#first").animate({
top: 10
}, 400);
}, 200);
});
$("#second").css("top", -1000);
$("#2nd").on('click', function() {
setTimeout(function() {
$("#second").animate({
top: 10 + 45 + 15
}, 400);
}, 400);
});
$("#third").css("top", -1000);
$("#3rd").on('click', function() {
setTimeout(function() {
$("#third").animate({
top: 10 + 45 + 45 + 30
}, 400);
}, 600);
});
$("#four").css("top", -1000);
$("#4th").on('click', function() {
setTimeout(function() {
$("#four").animate({
top: 10 + 45 + 45 + 45 + 45
}, 400);
}, 800);
});
//EXIT
var elements = $('.menu');
elements.on('click', function() {
$(this).toggle();
var nextEleemnts = $(this).nextAll('.menu');
for (var i = 0; i < nextEleemnts.length; i++) {
var topPos = $(nextEleemnts[i]).position().top - 60;
$(nextEleemnts[i]).animate({
top: topPos
}, 400);
}
});
$('#four').on('click', function() {
window.location.reload();
});
});
このように、アイテムはクリックされた順序で表示され、現在の固定位置には表示されませんか? – Pevara
はい、私の意図です。 –