Sliding effect with bounce I have used animate.css and jQuery as external libs. Is there a better way of doing what I have done with jQuery?

DEMO



$(document).ready(function () {

    $('#test li').on('click', function () {

        var className = $(this).attr('class');
        $('#test2 &gt; li').each(function () {

            var prodName = $(this).data('prod');


            if (prodName == className) {

                $('#test2 &gt; li').removeClass('bounceInRight').addClass('bounceOutRight');
                $this = $(this);
                setTimeout(function () {
                    console.log(this);
                    $('#test2 &gt; li').addClass('hide')
                    $this.removeClass('hide bounceOutRight').addClass('bounceInRight');
                }, 400);


            }
        });
    })
});
ul#test &gt; 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 &gt; 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;
}
&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"&gt;&lt;/script&gt;
&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.6/animate.min.css"&gt;&lt;/script&gt;
&lt;link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.6/animate.min.css"&gt;
&lt;ul id="test"&gt;
    &lt;li class="a"&gt;1&lt;/li&gt;
    &lt;li class="b"&gt;2&lt;/li&gt;
    &lt;li class="c"&gt;3&lt;/li&gt;
&lt;/ul&gt;
&lt;ul id="test2"&gt;
    &lt;li data-prod="a" class="animated"&gt;1&lt;/li&gt;
    &lt;li data-prod="b" class="animated"&gt;2&lt;/li&gt;
    &lt;li data-prod="c" class="animated"&gt;3&lt;/li&gt;
&lt;/ul&gt;
Your demonstration could benefit from better semantic markup.  In particular, the numbers on the left should be treated as navigation links, whose target is the item to be animated.  If you remove all JavaScript and CSS, the functionality degrades gracefully.

An additional benefit is that the link directly identifies the item to be manipulated, so that you don't have to locate the element yourself using a var prodName = $(this).data('prod'); if (prodName == className) … check.

You don't need to define a .hide { display: none; } rule in your CSS.  The jQuery $.hide() and $.show() methods can do that job.

Take care to localize $this.



$(document).ready(function () {
    $('nav &gt; ul &gt; li &gt; a').on('click', function () {
        $('li.animated').hide();
        $($(this).attr('href')).each(function () {
            var $this = $(this);
            $this.show()
                 .removeClass('bounceInRight')
                 .addClass('bounceOutRight');
            setTimeout(function () {
                $this.removeClass('bounceOutRight')
                     .addClass('bounceInRight');
            }, 400);
        });
    })
});
nav &gt; ul &gt; li {
    display: inline-block;
    padding: 10px;
}
nav &gt; ul &gt; li &gt; a {
    color: black;
    text-decoration: none;
}
ul {
    position: fixed;
    top: 0;
    right: 0;
    list-stlye: none;
}
nav &gt; ul {
    right: auto;
    left: 0;
}
li.animated {
    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;
}
&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"&gt;&lt;/script&gt;
&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.6/animate.min.css"&gt;&lt;/script&gt;
&lt;link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.6/animate.min.css"&gt;
&lt;nav&gt;
    &lt;ul&gt;
        &lt;li&gt;&lt;a href="#a"&gt;1&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="#b"&gt;2&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="#c"&gt;3&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
&lt;/nav&gt;
&lt;ul&gt;
    &lt;li class="animated" id="a"&gt;1&lt;/li&gt;
    &lt;li class="animated" id="b"&gt;2&lt;/li&gt;
    &lt;li class="animated" id="c"&gt;3&lt;/li&gt;
&lt;/ul&gt;