- Notifications
You must be signed in to change notification settings - Fork230
Introduction to browser events#392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
536f94280295392b6127562414a2cd05e8e721c0cd7c0d1aeFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| Podemos usar `this`en el handlerpara referenciar "al propio elemento" aquí: | ||
| ```html run height=50 | ||
| <input type="button" onclick="this.hidden=true" value="Clickpara ocultar"> | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,11 +2,11 @@ importance: 5 | ||
| --- | ||
| #¿Qué handlersse ejecutan? | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Correcto, pero tengo una duda ¿no hemos traducido handler en anteriores artículos? Creo que es mejor mantener esa consistencia. No importa si se traduce como manejador o controlador, pero creo que es mejor traducirlo. | ||
| Hay un botón en la variable.No hayhandlersen él. | ||
| ¿Qué handlersse ejecutan con elclickdespués del siguiente código? ¿Qué alertas se muestran? | ||
| ```js no-beautify | ||
| button.addEventListener("click", () => alert("1")); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| Primero necesitamos elegir un método para posicionar el balón. | ||
| No podemos usar `position:fixed`para ello, porque al desplazar la página se movería el balón del campo. | ||
| Así que deberíamos usar `position:absolute`y, para que el posicionamiento sea realmente sólido, hacer que`field`sea posicione a sí mismo. | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. entendemos "solido" ? en ingles "solid" es una persona confiable, ¿el ruso lo esta usando asi? seria medio rebuscado la cosa que no "posicionamiento solido" que se refiere a coordenadas relativass al contenido no al browser ok no importa | ||
| Entonces el balón se posicionará en relación al campo: | ||
| ```css | ||
| #field { | ||
| @@ -16,36 +16,36 @@ Then the ball will be positioned relatively to the field: | ||
| #ball { | ||
| position: absolute; | ||
| left: 0; /*relativo al predecesor más cercano (field) */ | ||
| top: 0; | ||
| transition: 1s all; /*AnimaciónCSSpara que left/tophagan al balón volar */ | ||
| } | ||
| ``` | ||
| Lo siguiente es asignar el`ball.style.left/top` correcto. Ahora contienen coordenadas relativas al campo. | ||
| Aquí está la imagen: | ||
|  | ||
| Tenemos`event.clientX/clientY`, las cuales son las coordenadas delclick relativas a la ventana. | ||
| Para obtener la coordenada`left`del click relativa al campo necesitamos restar el limite izquierdo del campo y el ancho del borde: | ||
| ```js | ||
| let left = event.clientX - fieldCoords.left - field.clientLeft; | ||
| ``` | ||
| Normalmente `ball.style.left`significa el "borde izquierdo del elemento" (el balón).Por lo que si asignamos ese`left`,entonces el borde del balón, no el centro, es el que se encontraría debajo delcursor del mouse. | ||
| Necesitamos mover la mitad del ancho del balón a la izquierda y la mitad del alto hacia arriba para que quede en el centro. | ||
| Por lo que el`left`final debería ser: | ||
| ```js | ||
| let left = event.clientX - fieldCoords.left - field.clientLeft - ball.offsetWidth/2; | ||
| ``` | ||
| La coordenadaverticales calculada usando la misma lógica. | ||
| Por favor, nota que el ancho/alto del balón se debe conocer al momento que accedemos a`ball.offsetWidth`.Se debe especificar en HTMLo CSS. | ||
Uh oh!
There was an error while loading.Please reload this page.