2 つの異なる HTML 要素のスライド効果を作成する必要がありますが、このアニメーションは同時に実行する必要があります。
jquery.animate() 関数を使用する方法はありますか?
2 つの異なる HTML 要素のスライド効果を作成する必要がありますが、このアニメーションは同時に実行する必要があります。
jquery.animate() 関数を使用する方法はありますか?
ここでは、jQueryを使用して2つの異なるHTML要素をアニメーション化する方法を示す完全なビンを作成しました。以下のデモリンク:
デモ: http ://codebins.com/bin/4ldqp9a
HTML:
<div id="panel1" class="edge">
<div class="box" style="top:30; background:#f8a2a4;">
</div>
</div>
<div id="panel2" class="edge">
<div class="box" style="top:120; background:#5599fd;">
</div>
</div>
<br/>
<input type="button" id="btn1" value="Animate Block1" />
<input type="button" id="btn2" value="Animate Block2" />
<input type="button" id="btn3" value="Animate Both" />
CSS:
body{
background:#ffffef;
}
.edge{
width:500px;
height:70px;
border:1px solid #3377af;
padding:5px;
margin-top:10px;
}
.box{
position:absolute;
left:10;
width:40px;
height:40px;
border:1px solid #a82244;
}
JQuery:
$(function() {
$("#btn1").click(function() {
var move = "";
if ($(".box", $("#panel1")).css('left') == "10px") {
move = "+=" + ($("#panel1").width() - 35);
} else {
move = "-=" + ($("#panel1").width() - 35);
}
$(".box", $("#panel1")).animate({
left: move
}, 500, function() {
if ($(this).css('left') == "475px") {
$(this).css('background', '#afa799');
} else {
$(this).css('background', '#f8a2a4');
}
});
});
$("#btn2").click(function() {
var move = "";
if ($(".box", $("#panel2")).css('left') == "10px") {
move = "+=" + ($("#panel2").width() - 35);
} else {
move = "-=" + ($("#panel2").width() - 35);
}
$(".box", $("#panel2")).animate({
left: move
}, 500, function() {
if ($(this).css('left') == "475px") {
$(this).css('background', '#afa799');
} else {
$(this).css('background', '#5599fd');
}
});
});
//Call Event Con-currently for both blocks
$("#btn3").click(function() {
$("#btn1").add("#btn2").click();
});
});
私は単にdivを移動し、同時にIMGを移動しようとしていました
2 つの .animate() が同時に自動的に実行されることを忘れていました。
時間ロスすみません…