Skip to content

Commit 1926818

Browse files
author
vavimayor159
committed
Iniciando segunda parte de la traduccion
1 parent 46ffdf1 commit 1926818

File tree

1 file changed

+86
-79
lines changed

1 file changed

+86
-79
lines changed

14_dom.md

Lines changed: 86 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -476,78 +476,84 @@ if}}
476476

477477
{{index "href attribute", [DOM, attributes]}}
478478

479-
Some element ((attribute))s, such as `href` for links, can be accessed
480-
through a property of the same name on the element's ((DOM))
481-
object. This is the case for most commonly used standard attributes.
479+
Los ((attributo))s de algunos elementos, como `href` par los enlaces
480+
pueden ser accedidos a traves de una propiedad con el mismo nombre en
481+
el objeto ((DOM)) del elemento. Este es el caso para los atributos
482+
estandar más comunmente utilizados.
482483

483484
{{index "data attribute", "getAttribute method", "setAttribute method", attribute}}
484485

485-
But HTML allows you to set any attribute you want on nodes. This can
486-
be useful because it allows you to store extra information in a
487-
document. If you make up your own attribute names, though, such
488-
attributes will not be present as properties on the element's node.
489-
Instead, you have to use the `getAttribute` and `setAttribute` methods
490-
to work with them.
486+
Pero HTML te permite establecer cualquier atributo que quieras en los
487+
nodos. Esto puede ser util debido a que te permite almacenar información
488+
extra en un documento. Sin embargo, si creas tus propios nombres de
489+
atributo, dichos atributos no estarán presentes como propiedades en el
490+
nodo del elemento. En vez de eso, tendras que utilizar los métodos
491+
`getAttribute` y `setAttribute` para trabajar con ellos.
491492

492493
```{lang: "text/html"}
493-
<p data-classified="secret">The launch code is 00000000.</p>
494-
<p data-classified="unclassified">I have two feet.</p>
494+
<p data-classified="secreto">El código de lanzamiento es: 00000000.</p>
495+
<p data-classified="no-classificado">Yo tengo dos pies.</p>
495496
496497
<script>
497498
let paras = document.body.getElementsByTagName("p");
498499
for (let para of Array.from(paras)) {
499-
if (para.getAttribute("data-classified") == "secret") {
500+
if (para.getAttribute("data-classified") == "secreto") {
500501
para.remove();
501502
}
502503
}
503504
</script>
504505
```
505506

506-
It is recommended to prefix the names of such made-up attributes with
507-
`data-` to ensure they do not conflict with any other attributes.
507+
Se recomienda anteponer los nombres de dichos atributos inventados con
508+
`data-` para asegurarse de que no conflictuan con ningun otro atributo.
508509

509510
{{index "getAttribute method", "setAttribute method", "className property", "class attribute"}}
510511

511-
There is a commonly used attribute, `class`, which is a ((keyword)) in
512-
the JavaScript language. For historical reasons—some old JavaScript
513-
implementations could not handle property names that matched
514-
keywords—the property used to access this attribute is called
515-
`className`. You can also access it under its real name, `"class"`, by
516-
using the `getAttribute` and `setAttribute` methods.
512+
Existe un atributo comunmente usado, `class`, que es una ((palabra clave))
513+
en el lenguaje JavaScript. Por motivos historicos, algunas
514+
implementaciones antiguas de JavaScript podrian no manejar nombres de
515+
propiedades que coincidan con las palabras clave-la propiedad utilizada
516+
para acceder a este atributo tiene por nombre `className`. Tambien
517+
puedes acceder a el bajo su nombre real, `"class"`, utilizando los
518+
metodos `getAttribute` and `setAttribute`.
517519

518520
## Layout
519521

520522
{{index layout, "block element", "inline element", "p (HTML tag)", "h1 (HTML tag)", "a (HTML tag)", "strong (HTML tag)"}}
521523

522-
You may have noticed that different types of elements are laid out
523-
differently. Some, such as paragraphs (`<p>`) or headings (`<h1>`),
524-
take up the whole width of the document and are rendered on separate
525-
lines. These are called _block_ elements. Others, such as links
526-
(`<a>`) or the `<strong>` element, are rendered on the same line with
527-
their surrounding text. Such elements are called _inline_ elements.
524+
Tal vez hayas notado que diferentes tipos de elementos se exponen
525+
de manera distinta. Algunos, como en el caso de los parrafos
526+
(`<p>`) o encabezados (`<h1>`), ocupan todo el ancho del documento
527+
y se renderizan en lineas separadas. A estos se les conoce como
528+
elementos _block_ (bloque). Otros, como los enlaces (`<a>`) o el
529+
elemento `<strong>`, se renderizan en la misma linea con su texto
530+
circundante. Dichos elementos se les conoce como elementos
531+
_inline_ (en la misma linea).
528532

529533
{{index drawing}}
530534

531-
For any given document, browsers are able to compute a layout, which
532-
gives each element a size and position based on its type and content.
533-
This layout is then used to actually draw the document.
535+
Para cualquier documento dado, los navegadores son capaces de calcular
536+
una estructura _(layout)_, que le da a cada elemento un tamaño y una
537+
posición basada en el tipo y el contenido. Luego, esta estructura se
538+
utiliza para trazar el documento.
534539

535540
{{index "border (CSS)", "offsetWidth property", "offsetHeight property", "clientWidth property", "clientHeight property", dimensions}}
536541

537-
The size and position of an element can be accessed from JavaScript.
538-
The `offsetWidth` and `offsetHeight` properties give you the space the
539-
element takes up in _((pixel))s_. A pixel is the basic unit of
540-
measurement in the browser. It traditionally corresponds to the
541-
smallest dot that the screen can draw, but on modern displays, which
542-
can draw _very_ small dots, that may no longer be the case, and a
543-
browser pixel may span multiple display dots.
542+
Se puede acceder al tamaño y la posición de un elemento pueden desde
543+
JavaScript. Las propiedades `offsetWidth` y `offsetHeight` te dan el
544+
espacio que el elemento ocupa en ((pixel))es. Un pixel es la unidad
545+
basica de las medidas del navegador. Tradicionalmente correspondia al
546+
punto más pequeño que la pantalla podía trazar, pero en los monitores
547+
modernos, que pueden trazar puntos _muy_ pequeños, este puede no ser
548+
más el caso, por lo que un pixel del navegado puede abarcar varios
549+
puntos en la pantalla.
544550

545-
Similarly, `clientWidth` and `clientHeight` give you the size of the
546-
space _inside_ the element, ignoring border width.
551+
De manera parecida, `clientWidth` y `clientHeight` te dan el tamaño
552+
del espacio _dentro_ del elemento, ignorando la anchura del borde.
547553

548554
```{lang: "text/html"}
549555
<p style="border: 3px solid red">
550-
I'm boxed in
556+
Estoy dentro de una caja
551557
</p>
552558
553559
<script>
@@ -559,7 +565,7 @@ space _inside_ the element, ignoring border width.
559565

560566
{{if book
561567

562-
Giving a paragraph a border causes a rectangle to be drawn around it.
568+
Darle un borde a un párrafo hace que se dibuje un rectángulo a su alrededor.
563569

564570
{{figure {url: "img/boxed-in.png", alt: "A paragraph with a border",width: "8cm"}}}
565571

@@ -569,61 +575,62 @@ if}}
569575

570576
{{id boundingRect}}
571577

572-
The most effective way to find the precise position of an element on
573-
the screen is the `getBoundingClientRect` method. It returns an object
574-
with `top`, `bottom`, `left`, and `right` properties, indicating the
575-
pixel positions of the sides of the element relative to the top left
576-
of the screen. If you want them relative to the whole document, you
577-
must add the current scroll position, which you can find in the
578-
`pageXOffset` and `pageYOffset` bindings.
578+
La manera más efectiva de encontrar la posición precisa de un elemento
579+
en la pantalla es el método `getBoundingClientRect`. Este devuelve un
580+
objeto con las propiedades `top`, `bottom`, `left`, y `right`, indicando
581+
las posiciones de pixeles de los lados el elemento en relacion con la
582+
parte superior izquierda de la pantalla. Si los quieres relativos a
583+
todo el documento, deberas agregar la posición actual del scroll, la
584+
cual puedes obtener en los _bindings_ `pageXOffset` y `pageYOffset`.
579585

580586
{{index "offsetHeight property", "getBoundingClientRect method", drawing, laziness, performance, efficiency}}
581587

582-
Laying out a document can be quite a lot of work. In the interest of
583-
speed, browser engines do not immediately re-layout a document every
584-
time you change it but wait as long as they can. When a JavaScript
585-
program that changed the document finishes running, the browser will
586-
have to compute a new layout to draw the changed document to
587-
the screen. When a program _asks_ for the position or size of
588-
something by reading properties such as `offsetHeight` or calling
589-
`getBoundingClientRect`, providing correct information also requires
590-
computing a ((layout)).
588+
Estructurar un documento puede requerir mucho trabajo. En los
589+
intereses de velocidad, los motores de los navegadores no
590+
reestructuran inmediatamente un documento cada vez que lo cambias,
591+
en cambio, se espera lo más que se pueda. Cuando un programa de
592+
JavaScript que modifica el documento termina de ejecutarse, el
593+
navegador tendra que calcular una nueva estructura para trazar el
594+
documento actualizado en la pantalla. Cuando un programa _solicita_
595+
la posición o el tamaño de algo, leyendo propiedades como `offsetHeight`
596+
o llamando a `getBoundingClientRect`, proveer la informacion correcta
597+
también requiere que se calcule una nueva estructura.
591598

592599
{{index "side effect", optimization, benchmark}}
593600

594-
A program that repeatedly alternates between reading DOM layout
595-
information and changing the DOM forces a lot of layout computations
596-
to happen and will consequently run very slowly. The following code is
597-
an example of this. It contains two different programs that build up a
598-
line of _X_ characters 2,000 pixels wide and measures the time each
599-
one takes.
601+
A un programa que repeditamente alterna entre leer la información de la
602+
estructura DOM y cambiar el DOM fuerza a que hayan bastantes calculos
603+
de estructura, y por consecuencia se ejecutara lentamente. El siguiente
604+
codigo es un ejemplo de esto. Contiene dos programas diferentes que
605+
construyen una linea de _X_ caracteres con 2,000 pixeles de ancho y
606+
que mide el tiempo que toma cada uno.
600607

601608
```{lang: "text/html", test: nonumbers}
602-
<p><span id="one"></span></p>
603-
<p><span id="two"></span></p>
609+
<p><span id="uno"></span></p>
610+
<p><span id="dos"></span></p>
604611
605612
<script>
606-
function time(name, action) {
607-
let start = Date.now(); // Current time in milliseconds
608-
action();
609-
console.log(name, "took", Date.now() - start, "ms");
613+
function tiempo(nombre, accion) {
614+
let inicio = Date.now(); // Current time in milliseconds
615+
accion();
616+
console.log(nombre, "utilizo", Date.now() - inicio, "ms");
610617
}
611618
612-
time("naive", () => {
613-
let target = document.getElementById("one");
614-
while (target.offsetWidth < 2000) {
615-
target.appendChild(document.createTextNode("X"));
619+
tiempo("inocente", () => {
620+
let objetivo = document.getElementById("uno");
621+
while (objetivo.offsetWidth < 2000) {
622+
objetivo.appendChild(document.createTextNode("X"));
616623
}
617624
});
618-
// → naive took 32 ms
625+
// → inocente utilizo 32 ms
619626
620-
time("clever", function() {
621-
let target = document.getElementById("two");
622-
target.appendChild(document.createTextNode("XXXXX"));
623-
let total = Math.ceil(2000 / (target.offsetWidth / 5));
624-
target.firstChild.nodeValue = "X".repeat(total);
627+
tiempo("ingenioso", function() {
628+
let objetivo = document.getElementById("dos");
629+
objetivo.appendChild(document.createTextNode("XXXXX"));
630+
let total = Math.ceil(2000 / (objetivo.offsetWidth / 5));
631+
objetivo.firstChild.nodeValue = "X".repeat(total);
625632
});
626-
// → clever took 1 ms
633+
// → ingenioso utilizo 1 ms
627634
</script>
628635
```
629636

0 commit comments

Comments
 (0)