I have following code pieces
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;
}
And this 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);
}
});
})
});
Here is the DEMO
I have few questions
- For each click on
liofulwith id#testit animates the appropriateliofulthat has id#test2. How do I animate each div inlis asfadeInTop(animate.css) one after another without using classes and ids (just using tag selectors) once thelihas completed the animation. - Is there a better way of doing what i have done with jquery with better performance. I have added this part of question in codereview