【发布时间】:2015-06-23 18:58:22
【问题描述】:
我有以下代码片段
HTML
<ul id="test">
<li class="a">1</li>
<li class="b">2</li>
<li class="c">3</li>
</ul>
<ul id="test2">
<li data-prod="a" class="animated">
<div>1</div>
<div>2</div>
<div>3</div>
</li>
<li data-prod="b" class="animated hide">
<div>1</div>
<div>2</div>
<div>3</div>
</li>
<li data-prod="c" class="animated hide">
<div>1</div>
<div>2</div>
<div>3</div>
</li>
</ul>
CSS
ul#test > li {
display: inline-block;
padding: 10px;
cursor: pointer;
}
#test {
position: fixed;
top: 0;
left: 0;
}
#test2 {
position: fixed;
top: 0;
right: 0;
list-style: none;
}
#test2 > li {
background: yellow;
width: 350px;
height: 600px;
/* transition: height 0.3s ease, width 0.2s ease;*/
overflow: hidden;
margin-top: -30px;
padding-top: 30px;
margin-right: -50px;
}
.hide {
display: none;
}
还有这个 jquery
$(document).ready(function () {
$('#test li').on('click', function () {
var className = $(this).attr('class');
$('#test2 > li').each(function () {
var prodName = $(this).data('prod');
if (prodName == className) {
$('#test2 > li').removeClass('bounceInRight').addClass('bounceOutRight');
$this = $(this);
setTimeout(function () {
console.log(this);
$('#test2 > li').addClass('hide')
$this.removeClass('hide bounceOutRight').addClass('bounceInRight');
}, 400);
}
});
})
});
这里是DEMO
我有几个问题
- 每次点击
li或ul,id 为#test,它都会为 适当的li的ul具有ID#test2。如何为lis 中的每个 div 设置动画为fadeInTop(animate.css) 一个接一个没有 一旦li完成动画,就使用类和ID(仅使用标签选择器)。 - 有没有更好的方法来做我用 jquery 所做的事情,并且性能更好。我在codereview 中添加了这部分问题
【问题讨论】:
-
你看过内置的jquery函数吗,比如hide,fadeIn and fadeOut?
-
@Phoenix 是的,但我想用 animate.css 和 jquery 没有从顶级动画中淡入淡出
-
如果你在有效果且没有css文件的动画之后试试这个 -- julian.com/research/velocity
-
@Tasos 谢谢你的链接:)
标签: javascript jquery css css-animations animate.css