Elastic In/Out Sliding

Simple example of applying an elastic easing to an animated element in both directions.

by Travis Almand

HTML

<p>Click the box to have the item slide in and out with an elastic easing both ways.</p>

<div id='container'>
    <div id='slide'><h2>slider</h2></div>
</div>

CSS

html {
  box-sizing: border-box;
}
*, *:before, *:after {
  box-sizing: inherit;
}
h2 { text-align: center; }

#container {
    border: 1px solid black;
    height: 300px;
    overflow: hidden;
    position: relative;
    width: 200px;
}
#slide {
    border-top: 1px inset gainsboro;
    height: 100%;
    left: 0;
    position: absolute;
    top: 0;
    width: 100%;
    transform: translate3d(0, 100%, 0);
    transition: all 0.5s cubic-bezier(.5,-0.5,.5,1);
}
#slide.show {
    transform: translate3d(0, 0, 0);
    transition-timing-function: cubic-bezier(.5,0,.5,1.5);
}

JavaScript

$('#container').on('click', function () {
    $('#slide').toggleClass('show');
});