我有以下... jsFiddle
CSS
#box_1 {
position:absolute;
height:50px;
width:50px;
background-color:red;
top:10px;
left:10px;
text-align:center;
color:#FFFFFF;
}
#box_2 {
position:absolute;
height:50px;
width:50px;
background-color:blue;
top:10px;
left:70px;
text-align:center;
color:#FFFFFF;
}
#box_3 {
position:absolute;
height:50px;
width:50px;
background-color:green;
top:10px;
left:130px;
text-align:center;
color:#FFFFFF;
}
#box_4 {
position:absolute;
height:50px;
width:50px;
background-color:yellow;
top:10px;
left:190px;
text-align:center;
}
#box_5 {
position:absolute;
height:110px;
width:110px;
background-color:purple;
top:100px;
left:70px;
}
#box_6 {
position:absolute;
height:25px;
width:50px;
background-color:black;
top:20px;
left:300px;
text-align:center;
color:#FFFFFF;
}
jQuery
$('#box_1').click(function() {
$('#box_5').animate({
top: '170px'
}, 300);
});
$('#box_2').click(function() {
$('#box_5').animate({
left: '170px'
}, 600);
});
$('#box_3').click(function() {
$('#box_1').trigger('click');
$('#box_2').trigger('click');
});
$('#box_4').click(function() {
$('#box_5').animate({
top: '170px'
}, 300);
$('#box_5').animate({
left: '170px'
}, 600);
});
$('#box_6').click(function() {
$('#box_5').animate({
top: '100px'
}, 200);
$('#box_5').animate({
left: '70px'
}, 200);
});
HTML
<div id="box_1">
Down
</div>
<div id="box_2">
Right
</div>
<div id="box_3">
Both
</div>
<div id="box_4">
Both
</div>
<div id="box_5"></div>
<div id="box_6">
Reset
</div>
而且我想知道是否有可能同时触发 box_3 上的两个 .trigger 事件(其中带有“Both”的绿色方块),所以不要让紫色框先向下然后再向右,让它启动它们两者同时在页面上对角移动一点,然后在完成左侧 600ms 动画之后的剩余 300ms 之前。
理想情况下,我想保留 box_3 .click 以触发 box_1 和 box_2 点击,但让它们同时启动。
如果这不可能,是否可以结合
$('#box_5').animate({
top: '170px'
}, 300);
$('#box_5').animate({
left: '170px'
}, 600);
在 Yellow box_4 上,所以它们同时开始?
所以,事件的顺序是,
- 单击 Box_3 (.trigger) 或 Box_4 (.animate)。
- 方框 5 沿对角线向下和向右移动。
- 单击下移动画完成后 300 毫秒
- 单击右移动画完成后 600 毫秒
谁能帮我?
如果可以两种方式都这样做,您能否将它们都显示给我,以便我保留它们以供将来参考。