我试着阅读了如何使用停止符,并在此处查看其他答案。现在修改这段代码太久了。我似乎无法让这部动画始终保持平行。jQuery - 在嵌套动画序列中使用停止以正确回滚mouseleave上的所有动画
要么它在某个点停下来,要么保持排队动画的底线(见下面的代码)。无论哪种方式,我无法弄清楚在哪里停止让这个工作正常。
$(".property-wrapper").hover(function(e){
var lines = new Array();
lines.push($(this).find(".line-top"));
lines.push($(this).find(".line-left"));
lines.push($(this).find(".line-right"));
lines.push($(this).find(".line-bottom-right"));
lines.push($(this).find(".line-bottom-left"));
if(e.type == "mouseenter")
{
// Animate, starting from top, and going parallell towards the bottom. Then the bottom ones meet eachother.
// The motion forms a square
/*
Index 0 starts (from main.css) on left:50%; and animates to 0 while also animating width to 100%, giving
the illusion of it "shooting" out in both directions
Here is a representation of the indices and their direction of animation
<---------0--------->
1 2
| |
| |
| |
|4--------><-------3|
*/
$(lines[0]).animate({width:"100%", left:0}, 'fast', function(){
$(lines[1]).animate({height:"100%"}, 'slow' , function(){
$(lines[4]).animate({width:"50%"}, 'slow');
});
$(lines[2]).animate({height:"100%"}, 'slow', function(){
$(lines[3]).animate({width:"50%"}, 'slow');
});
});
}
else
{
// Reverse the animation on mouseenter
$(lines[3]).animate({width:0}, 'fast', function() {
$(lines[2]).animate({height:0}, 'slow', function(){
$(lines[0]).animate({width:0, left:"50%"}, 'fast');
});
});
$(lines[4]).animate({width:0}, 'fast', function() {
$(lines[1]).animate({height:0}, 'slow');
});
}
});
希望任何人都可以帮忙! 感谢
编辑:这基本上是它是如何设置:
<div>
<div class="line-top"></div>
<div class="line-left"></div>
<div class="line-right"></div>
<div class="line-bottom-right"></div>
<div class="line-bottom-left"></div>
</div>
这里是CSS。行div的父母是相对位置,并且这些行是绝对的以控制相对于父母的位置。
.line-top, .line-left, .line-right, .line-bottom-right, .line-bottom-left
{ background:red; position:absolute; }
.line-top { height:1px; width:0; left:50%; top:0; }
.line-left { width:1px; height:0; left:0; top:0; }
.line-right { width:1px; height:0; right:0; top:0; }
.line-bottom-right { height:1px; width:0; right:0; bottom:0; }
.line-bottom-left { height:1px; width:0; left:0; bottom:0; }
你能分享任何html或做小提琴吗?我想我知道在哪里停止,但我不知道如何建立你的html,这对测试它很重要。 – 2013-03-06 17:23:08
是的。添加到OP! – 2013-03-06 18:04:07