Deprecated: Creation of dynamic property wpdb::$categories is deprecated in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/wp-db.php on line 760 Deprecated: Creation of dynamic property wpdb::$post2cat is deprecated in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/wp-db.php on line 760 Deprecated: Creation of dynamic property wpdb::$link2cat is deprecated in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/wp-db.php on line 760 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/comment-template.php on line 1745 Deprecated: wp_getimagesize(): Implicitly marking parameter $image_info as nullable is deprecated, the explicit nullable type must be used instead in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/media.php on line 5180 Deprecated: Creation of dynamic property POMO_FileReader::$is_overloaded is deprecated in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/pomo/streams.php on line 26 Deprecated: Creation of dynamic property POMO_FileReader::$_pos is deprecated in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/pomo/streams.php on line 29 Deprecated: Creation of dynamic property POMO_FileReader::$_f is deprecated in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/pomo/streams.php on line 160 Deprecated: Creation of dynamic property MO::$_gettext_select_plural_form is deprecated in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/pomo/translations.php on line 293 Deprecated: Creation of dynamic property WP_Block_Type::$skip_inner_blocks is deprecated in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/class-wp-block-type.php on line 357 Deprecated: Calling get_class() without arguments is deprecated in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/class-wp-http.php on line 328 Deprecated: Return type of Requests_Cookie_Jar::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/Requests/Cookie/Jar.php on line 63 Deprecated: Return type of Requests_Cookie_Jar::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/Requests/Cookie/Jar.php on line 73 Deprecated: Return type of Requests_Cookie_Jar::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/Requests/Cookie/Jar.php on line 89 Deprecated: Return type of Requests_Cookie_Jar::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/Requests/Cookie/Jar.php on line 102 Deprecated: Return type of Requests_Cookie_Jar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/Requests/Cookie/Jar.php on line 111 Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 40 Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 51 Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 68 Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 82 Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 91 Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/class-wp-term.php on line 198 Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /mnt/web522/e0/75/511171875/htdocs/blog/wp-includes/class-wp-term.php on line 198 Ideas Fugaces -
Warning: Undefined array key 0 in /mnt/web522/e0/75/511171875/htdocs/blog/wp-content/themes/bootstrap_blog/index.php on line 11

Transiciones con CSS

Por: Germanet

01 Definición

Las transiciones son animaciones simples, que permiten cambiar los valores de las propiedades CSS de manera gradual, proporcionando una duración. La propiedad Transition es, por tanto, el primer paso en CSS3 para lo que luego se conseguirá con la regla @keyframes, a la que dedicaremos un artículo próximamente. En este ejemplo también se ha utilizado la propiedad transform que permite que un objeto se pueda rotar, mover, inclinar, etc.

Transition (Sintaxis) Forma abreviada: las propiedades separadas por coma y los parámetros por espacio. El orden es importante.

transition: propiedad duración retraso, propiedad2 duración retraso;

Ej. transition: width 2s 1s; height 2s 1s;

Transform ( Sintaxis ) Ver lista completa de las propiedades en el enlace de referencia.

transform: propiedad (valor);

Ej. transform: rotate(15deg);

02 Componentes del ejemplo

Nota. Los valores CSS se muestran abajo, en la pestaña: Ver Código.

Banner

Es el contenedor y se ha posicionado de manera relativa, para que contenga el resto de elementos de forma absoluta, entre ellos, la imagen del fondo. Además, se le ha dado la propiedad overflow: hidden; para que todo lo que sobrepase los límites quede oculto.

Título

  • Se anima su posición de derecha (1300px) a izquierda (110px). Con la ayuda de javascript (JQuery), al cargar la página se le añade la clase "animado" que produce el cambio.
  • La propiedad transition, otorga 0.5 segundos a esta transición, que se realiza de forma lenta tanto al principio como al final (ease-in-out) y sin retraso..

Panel

  • Se desplaza hacia abajo. Al cargar la página se le añade la clase "animado", que lo coloca en su posición final. A la capa #panel, se la han dado unos valores para la transición de la posición (top) de 1.5 segundos, de forma rápida al comienzo y al final (ease) y sin retraso.

Auto

  • Se anima su posición de derecha a izquierda. Su transición, aplicada a la capa #auto es de 3 segundos y para la forma en que debe hacerlo se usa un función (cubic-bezier) que consta de 4 valores (0.31, 1.58, 0.35, 1.08), y que consigue el efecto de retroceso. Esta acción tiene un retraso es de 1 segundo, para que llegue el último..

Ruedas

  • Son elementos independientes (#rueda_1 y #rueda_2) porque además de desplazarse hacia la izquierda de la misma forma que el auto, deben girar. La posición final está condicionada por la del auto, al igual que el movimiento, y por eso deben tener los mismos valores de la función cubic-bezier (0.31, 1.58, 0.35, 1.08). También el retraso debe ser de 1 segundo.
  • Para que roten, se le aplica la propiedad transform: rotate(-1080deg); y la propiedad transform-origin, para precisar el punto exacto del eje, sobre el que debe rotar la imagen.
Fuentes / Recursos

Transición en 3schools | Función cubic-bezier | Transform | Agregar Clase en W3Scool y aguí>

Problemas

  1. Las ruedas no giraban de manera armónica, lo hacían como si estuvieran descentradas.S/ Por alguna razón, el navegador no cogía automáticamente el centro de la imagen para rotar sobre los ejes. Tuve que especificar ese centro de rotación con la propiedad transform-origin: 50% 48% 0;.
Ver Código (+/-)

JQuery




CSS

#banner {
	width: 500px;
	height:320px;
	margin: 30px auto;
	position: relative;
	-webkit-perspective: 500px;
	-moz-perspective: 500px;
	-o-perspective: 500px;
	perspective: 500px;
	overflow: hidden;
}

#titulo {
	position: absolute;
	left: 1300px;
	top: 10px;
}

#titulo.animado {
	left: 110px;
	 -webkit-transition: all .5s ease-in-out;
	 -moz-transition: all .5s ease-in-out;
	 -o-transition: all .5s ease-in-out;
	 transition: left .5s ease-in-out;
}

#auto {
	position: absolute;
	top: 190px;
	left: 1000px;
}

#auto.animado {
	left:100px;
	-webkit-transition: all 3s ease;
	-moz-transition: all 3s ease;
	-o-transition: all 3s ease;
	transition: all 3s /*ease*/cubic-bezier(/*.42,1.35,.47,1.29*/.31, 1.58, .35, 1.08);
	-webkit-transition-delay: 1s;
	-moz-transition-delay: 1s;
	-o-transition-delay: 1s;
	transition-delay: 1s;
}

#panel {
	position: absolute;
	top: -1000px;
	left: 100px;
}

#panel.animado {
	top:70px;
	-webkit-transition: top 1.5s ease;
	-moz-transition: top 1.5s ease;
	-o-transition: top 1.5s ease;
	transition: top 1.5s ease;
}

#rueda_1 {
	position: absolute;
	left: 1060px;
	top: 227px;
}

#rueda_2 {
	position: absolute;
	left: 1290px;
	top: 227px;
}

.rueda {
	-webkit-transition-property: left, opacity, -webkit-transform;
	-webkit-transition-duration: 3s, 4s, 3s;
	-webkit-transition-timing-function: ease, ease, ease-out;
	-webkit-transition-delay: 1s, .5s, 1s;

	-moz-transition-property: left, opacity, -moz-transform;
	-moz-transition-duration: 3s, 4s, 3s;
	-moz-transition-timing-function: ease, ease, ease-out;
	-moz-transition-delay: 1s, .5s, 1s;

	-o-transition-property: left, opacity, -o-transform;
	-o-transition-duration: 3s, 4s, 3s;
	-o-transition-timing-function: ease, ease, ease-out;
	-o-transition-delay: 1s, .5s, 1s;

	transition-property: left, opacity, transform;
	transition-duration: 3s, 4s, 3s;
	transition-timing-function: /*ease*/cubic-bezier(/*.42,1.35,.47,1.29*/.31, 1.58, .35, 1.08), ease, /*ease-out*/ cubic-bezier(/*.42,1.35,.47,1.29*/.31, 1.58, .35, 1.08);
 	transition-delay: 1s, .5s, 1s;
}

#rueda_1.animar {
	left:158px;
}

#rueda_2.animar {
	left: 367px;
}

.rueda.animar {
	-webkit-transform: rotate(-1080deg);
	-moz-transform: rotate(-1080deg);
	-o-transform: rotate(-1080deg);
	transform: rotate(-1080deg);
	opacity: 1;
	transform-origin: 50% 48% 0;
}



postend.gif