jQuery animate example lesson 2
tutoring how to select and animate an element
HTML
<p id="btn">button</p>
<div id="test" class=""></div>
CSS
div{
position:absolute;
display:block;
height:80px;
width:80px;
left:50px;
top:50px;
background-color: blue;
cursor: pointer;
display:none;
}
p {
cursor: pointer;
}
@-webkit-keyframes open-popup {
0% {
-webkit-transform: scale(0.1);
transform: scale(0.1);
}
100% {
-webkit-transform: scale(1);
transform: scale(1);
}
}
@keyframes open-popup {
0% {
-webkit-transform: scale(0.1);
transform: scale(0.1);
}
100% {
-webkit-transform: scale(1);
transform: scale(1);
}
}
.open-popup {
-webkit-animation-name: open-popup;
animation-name: open-popup;
-webkit-animation-duration: 0.5s;
animation-duration: 0.5s;
-webkit-animation-timing-function: ease-in-out;
animation-timing-function: ease-in-out;
-webkit-animation-iteration-count: 1;
animation-iteration-count: 1;
}
JavaScript
$(function(){
$('#btn').click(function(){
$('#test').show();
$('#test').addClass("open-popup");
setTimeout(function () {
$('#test').removeClass("open-popup");
}, 500);
});
});