Audyx half-width panel adding animation

by sungsoonz

HTML

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<button>Add 3</button>
<div>
    <div class="row">
        <div class="col-xs-6">
            <div class="panel" id="panel_1">
                <h2>1</h2>
            </div>
        </div>
        <div class="col-xs-6">
            <div class="panel" id="panel_2">
                <h2>2</h2>
            </div>
            <div class="panel hidden" id="panel_3">
                <h2>3</h2>
            </div>
            <div class="panel" id="panel_4">
                <h2>4</h2>
            </div>
        </div>
    </div>
</div>

CSS

html, body {
    background: #eee;
    margin: 0;
    padding: 0;
}
button {
    position: fixed;
    right: 0;
    bottom: 0;
    z-index: 9999;
    background: #5b98cc;
    border-radius: 50%;
    border: 0;
    color: white;
    width: 60px;
    height: 60px;
}
.panel {
    background: #fff;
    padding: 15px;
    height: 200px;
    border-radius: 0;
}
.out {
    
}

#panel_1 {
    border-top: 3px solid red;
}
#panel_2 {
    border-top: 3px solid green;
}
#panel_3 {
    border-top: 3px solid blue;
}
#panel_4 {
    border-top: 3px solid purple;
}

JavaScript

$('button').click(function () {
    reposition( $('#panel_4') );
});

function reposition(panel) {
    panel.animate({
        "margin-left": '100%'
    }, 400, function() {
        panel.animate({
            "margin-left": '0'
        }, 400, function() {
           add( $('#panel_3') );
        });
    });
}

function add(panel) {
    panel.toggleClass('hidden');
}