Transition Tooltip

by Amaury Dalla Monta

HTML

<div id="content">Hover to show tooltip. Click to transform.</div>

CSS

#content {
    position: relative;
    width: 200px;
    height: 100px;
    background: beige;
    border: 1px solid black;
    border-radius: 5px;
    margin: 50px auto;
    padding: 5px;
    transition: all 500ms;
    -webkit-transition: all 500ms;
}
#content:before {
    content:'Tooltip';
    position: absolute;
    width: 100px;
    height: 25px;
    line-height: 25px;
    top: 0px;
    left: 25%;
    text-align: center;
    background: coral;
    border: 1px solid black;
    border-radius: 5px;
    opacity: 0;
    transition: all 250ms 750ms ease;
    -webkit-transition: all 250ms 750ms ease;
}
#content:hover:before {
    opacity: 1;
    transform: translateY(-30px);
    transition: all 500ms;
    -webkit-transform: translateY(-30px);
    -webkit-transition: all 500ms;
}
#content.clicked:before {
    opacity: 0;
    transition: all 500ms;
    -webkit-transition: all 500ms;
}
#content.clicked {
    width: 400px;
    height: 100px;
    transform: translateX(30px) translateY(30px);
    transition: all 500ms;
    -webkit-transform: translateX(30px) translateY(30px);
    -webkit-transition: all 500ms;
}

JavaScript

$("#content").on("click", function () {
    $(this).toggleClass("clicked");
    // toggle is only to let you reset the state quickly, otherwise addClass would suffice.
});