Creando un Robot animado Usando jQuery y CSS
Posted on feb 18 in Generalby adminPrint
Este hermoso ejercicio desde que lo lei me encanto y dedici publicarlo.
Los fondos fueron animados a diferentes velocidades con jQuery un plug-in por Alexander Farkas. Este efecto simula una falsa animacion en 3-D de fondo el denominado "efecto de paralaje" procedentes de la vieja escuela de video juegos de desplazamiento lateral.
El robot está compuesto de manera similar a la animación de fondo de escena por varias capas DIVs juntos para crear las diferentes piezas del robot. El paso final, fue la animación del robot con jQuery.
A continuacion el codigo HTML Usado:
Lo Siguiente es añadir la hoja de estilos, y el codigo es el siguiente:
-
h1, p { position: absolute; left: -9999px; }
-
-
div {position: relative;}
-
-
#wrapper { background: #bedfe4 url(../images/sun.png) no-repeat left -30px; border: 5px solid #402309;}
-
-
#cloud-01 { background: url(../images/clouds-01.png) no-repeat left -100px; }
-
-
#cloud-02 { background: url(../images/clouds-02.png) no-repeat left top; }
-
-
#mountains-03 { background: url(../images/mountain-03.png) no-repeat left bottom; }
-
-
#ground { background: url(../images/ground-05.png) no-repeat left bottom; }
-
-
#full-robot { width: 271px; }
-
-
#branding {
-
background: url(../images/robot-head.png) no-repeat center top;
-
width: 271px;
-
height: 253px;
-
z-index: 4;
-
}
-
-
#content {
-
background: url(../images/robot-torso.png) no-repeat center top;
-
width: 271px;
-
height: 164px;
-
z-index: 3;
-
margin-top: -65px;
-
}
-
-
#sec-content {
-
background: url(../images/robot-hips.png) no-repeat center top;
-
width: 271px;
-
height: 124px;
-
z-index: 2;
-
margin-top: -90px;
-
}
-
-
#footer {
-
background: url('../images/robot-legs.png') no-repeat center top;
-
width: 271px;
-
height: 244px;
-
z-index: 1;
-
margin-top: -90px;
-
}
Y posteriormente lo que le da vida a nuestro robot:
-
$(document).ready(function(){
-
$('#cloud-01').css({backgroundPosition: '0 -80px'});
-
$('#cloud-02').css({backgroundPosition: '0 -30px'});
-
$('#mountains-03').css({backgroundPosition: '0 50px'});
-
$('#trees-04').css({backgroundPosition: '0 50px'});
-
$('#ground').css({backgroundPosition: 'left bottom'});
-
$('#branding').css({backgroundPosition: 'center 0'});
-
$('#content').css({backgroundPosition: 'center 0'});
-
$('#sec-content').css({backgroundPosition: 'center 0'});
-
$('#footer').css({backgroundPosition: 'center 0'});
-
$('#wrapper').css({overflow: "hidden"});
-
-
$('#klicker').click(function(){
-
$('#cloud-01').animate({backgroundPosition: '(-500px -80px)'}, 20000);
-
$('#cloud-02').animate({backgroundPosition: '(-625px -30px)'}, 20000);
-
$('#mountains-03').animate({backgroundPosition: '(-2500px 50px)'}, 20000);
-
$('#ground').animate({backgroundPosition: '(-5000px bottom)'}, 20000);
-
-
startHim();
-
-
$("#full-robot").animate({left:"50%",marginLeft:"-150px"}, 2000);
-
setTimeout("leaveScreen()",15000);
-
});
-
-
});
-
-
var num = 1;
-
-
function startHim(){
-
num++;
-
$("#sec-content").animate({top:"-=5px"},150).animate({top:"+=5px"},150);
-
$("#content,#branding").animate({top:"-="+num+"px"},150).animate({top:"+="+num+"px"},150);
-
if(num<4){
-
setTimeout("startHim()",300);
-
} else {
-
setTimeout("bounceHim()",300);
-
}
-
}
-
-
function bounceHim(){
-
$("#sec-content,#branding").animate({top:"-=4px"},150).animate({top:"+=4px"},150);
-
$("#content").animate({top:"-=8px"},150).animate({top:"+=8px"},150);
-
setTimeout("bounceHim()",300);
-
}
-
-
function leaveScreen(){
-
$("#full-robot").animate({left:"100%",marginLeft:"0px"}, 2000);
-
}
Pueden ver el demo de la aplicacion aqui.
O leer el articulo del Autor aqui.
Related posts:
- Personalizando menus con listas & CSS
- Alternando el Color de las filas de una tabla usando Clases CSS


