我目前正在学习jQuery和一点TweenLite动画库(我想保持基本)。所以我正在构建一个作品集网格,但我想在点击元素时添加其他元素的淡入效果(从右侧滑入不重要)。
但是,我无法找到一种方法使得一个元素有一个要显示的盒子,而另一个元素有一个不同的盒子要显示,而不必一遍又一遍地复制代码并每次更改一个简单的数字。必须有一种方法可以使其正常工作而不需要重复编写代码。
我创建了一个CodePen来展示我的困境。
希望我描述这个问题很清楚 :)
HTML
但是,我无法找到一种方法使得一个元素有一个要显示的盒子,而另一个元素有一个不同的盒子要显示,而不必一遍又一遍地复制代码并每次更改一个简单的数字。必须有一种方法可以使其正常工作而不需要重复编写代码。
我创建了一个CodePen来展示我的困境。
希望我描述这个问题很清楚 :)
HTML
<div class="box">
<div class="show">Show 1</div>
</div>
<div class="bigbox">
<div class="removeit">
<div class="bigshow">Bigshow 1</div>
</div>
</div>
<div class="box">
<div class="show">Show 2</div>
</div>
<div class="bigbox">
<div class="removeit">
<div class="bigshow">Bigshow 2</div>
</div>
</div>
</div>
CSS
.container {
overflow: auto;
margin: 0 auto;
width:500px;
}
.box {
height:200px;
width:200px;
background:yellow;
text-align:center;
cursor:pointer;
margin:0 auto;
float:left;
margin-right:50px;
}
.bigbox {
height:100%;
width:100%;
background-color: grey;
z-index:100;
left:0;
opacity: 0;
position: fixed;
display:none;
top:0;
.removeit {
height:100px;
width: 100px;
top: 0;
right:0;
background-color: blue;
margin:0 auto;
cursor:pointer;
}
}
.show {
display:block;
}
.noscroll {
overflow:hidden;
}
Javascript
$(".box").click(function(){
$(".bigbox").addClass("show");
TweenLite.to($('.bigbox'), 0.5, {
opacity:1,
autoAlpha:1
});
});
$(".removeit").click(function(){
TweenLite.to($('.bigbox'), 0.5, {
autoAlpha:0,
opacity:0
});
});
这是一个Codepen代码示例