2014-01-12 31 views
0

首先,我想从@kgd打开这个解决方案,然后我想关闭它,当我点击另一个div ...在这个例子中的黄色div在小提琴?激活div函数并向后

var $a = $(".a"), 
 
    $b = $(".b"), 
 

 
function anim1() { 
 
    $b.animate({width: 395}, {duration: 500, complete: anim2}); 
 
} 
 

 
function anim2() { 
 
    $a.animate({top:"0px"}, {duration: 500}); 
 
} 
 

 
$(".b").click(function() { 
 
    anim1(); 
 
}); 
 

 
var $a1 = $(".a"), 
 
    $b1 = $(".b"), 
 
    
 
function anim10() { 
 
    $a1.animate({top:"-50px"}, {duration: 500}); 
 
} 
 

 
function anim20() { 
 
    $b1.animate({width: 137}, {duration: 500, complete: anim10}); 
 
} 
 

 
$(".ab").click(function() { 
 
    anim10(); 
 
});
.example { 
 
    width: 100%; 
 
} 
 

 
.a { 
 
    width: 600px; 
 
    height: 50px; 
 
    background-color: #888; 
 
    
 
    position: relative; 
 
    top: -50px; 
 
} 
 

 
.ab { 
 
    width: 50px; 
 
    height: 50px; 
 
    background-color: yellow; 
 
    float: left; 
 
} 
 

 
.b { 
 
    width: 137px; 
 
    height: 50px; 
 
    background-color: red; 
 
    margin-left: 50px; 
 
    float: left; 
 
} 
 

 
.c { 
 
    width: 395px; 
 
    height: 50px; 
 
    background-color: black; 
 
    margin-left: 100px; 
 
    
 
    position: relative; 
 
    top: 0px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> 
 
<div class="example"> 
 
    <div class="c"></div> 
 
    <div class="a"> 
 
     <div class="ab"></div> 
 
     <div class="b"></div> 
 
    </div> 
 
</div>

为什么我的解决方案不工作?

+0

@kgd这是我的问题:) – andre34

+0

1.请包含一个链接到“此解决方案从@kgd”。 2.kgd不会收到您评论的通知,因为@username仅适用于对该主题有所贡献的用户(即发布了答案或评论,或编辑了问题或答案)。在英语中,代词“I”应该总是大写。 –

+0

哦okey谢谢你的信息! – andre34

回答

1

代码更新here。你错过了一些逗号,你声明的变量阻止了代码的运行。

var $a = $(".a"), 
    $b = $(".b"); 

var $a1 = $(".a"), 
    $b1 = $(".b"); 

UPDATE

我做了一些小的变化,但它确实是很难确定你正在尝试基于代码和有限的解释完成的任务。我提供的是工作代码,所以也许这将有助于你朝着正确的方向前进?

+0

不错!但问题是,红色的div有相同的宽度,而不是137px ...当我点击黄色div – andre34

+0

,所以向后的div到顶部,然后红色的div必须从395px到137px ...在他的正常大小 – andre34

+0

http://jsfiddle.net/UqgXc/32/我在这里解决了它:) – andre34