我想切换一个将高度从10px添加到200px的div ..我的问题是,如果我再次点击它将从200px动画回到10px。而且我不知道该怎么做。
继承我的代码。
css
.container2 {
width: 100%;
height: 10px;
border: 1px;
}
.container .box {
padding: 10px;
margin: 10px;
background: blue;
display: none;
}
html
<div class="container2">
<div class="box bounceIn"></div>
</div>
javascript
var con = $('.container2');
var box = $('.box');
var click = $('.click');
click.click( function() {
TweenMax.to(con, 1, {height: '200px', ease:Bounce.easeOut});
});
答案 0 :(得分:1)
此代码将在两个州之间来回切换。
var clicked = false;
click.click(function() {
if(clicked){
TweenMax.to(con, 1, {height: '10', ease:Bounce.easeOut});
}else{
TweenMax.to(con, 1, {height: '200', ease:Bounce.easeOut});
}
clicked = !clicked;
});
答案 1 :(得分:0)
var clicked = false;
click.click( function() {
if(clicked == false){
TweenMax.to(con, 1, {height: '200px', ease:Bounce.easeOut});
}else{
TweenMax.to(con, 1, {height: '10px', ease:Bounce.easeOut});
}
});