1 2 3 4 5 6 7 8 9 10 11 12 13 | < div class = "container" > < h1 >Animación ejemplos</ h1 > < div id = "caja1" > </ div > < div id = "caja2" > </ div > < div id = "caja3" > </ div > < input type = "button" id = "anima1" value = "Animación 1 (jquery)" > < input type = "button" id = "anima3" value = "Animación 3 (jquery+CSS3)" > </ div > < script src = "js/codigo.js" type = "text/javascript" ></ script > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #caja 1 ,#caja 2 ,#caja 3 { background-color : red ; height : 150px ; width : 150px ; margin : 10px ; } @keyframes example { 0% { background-color : red ; left : 0px ; top : 0px ;} 25% { background-color :yellow; left : 200px ; top : 0px ;} 50% { background-color : blue ; left : 200px ; top : 200px ;} 75% { background-color : green ; left : 0px ; top : 200px ;} 100% { background-color : red ; left : 0px ; top : 0px ;} } /* The element to apply the animation to */ #caja 2 , .animacion { width : 100px ; height : 100px ; position : relative ; background-color : red ; animation-name : example; animation-duration : 4 s; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | $( function () { $( "#anima1" ).click( function () { $( "#caja1" ).animate({ left: '250px' , opacity: '0.5' , height: '200px' , width: '200px' }); }); $( '#anima3' ).click( function () { $( "#caja3" ).addClass( "animacion" ); }) }); |