Skip to content

Commit c65ea1a

Browse files
committed
Update 2-ui\1-document\11-coordinates\article.md
1 parent ac337e7 commit c65ea1a

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

2-ui/1-document/11-coordinates/article.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ elem.style.background = ''; // Error!
142142
```
143143
````
144144
145-
## Usare il posizionamento "fisso"
145+
## Utilizzare il posizionamento "fisso"
146146
147-
Most of time we need coordinates in order to position something.
147+
La maggior parte delle volte abbiamo bisogno delle coordinate per posizionare qualcosa.
148148
149-
To show something near an element, we can use `getBoundingClientRect` to get its coordinates, and then CSS `position` together with `left/top` (or `right/bottom`).
149+
Per mostrare qualcosa vicino un elemento, possiamo usare `getBoundingClientRect` per ricavare le sue coordinate e successivamente utilizzare la proprietà CSS `position` insieme a `left/top` (o `right/bottom`).
150150
151-
For instance, the function `createMessageUnder(elem, html)` below shows the message under `elem`:
151+
Per esempio la funzione `createMessageUnder(elem, html)` in basso, mostra un messaggio sotto `elem`:
152152
153153
```js
154154
let elem = document.getElementById("coords-show-mark");
@@ -172,32 +172,32 @@ function createMessageUnder(elem, html) {
172172
return message;
173173
}
174174
175-
// Usage:
176-
// add it for 5 seconds in the document
175+
// Esempio d'uso:
176+
// aggiunge il messaggio al documento per 5 secondi
177177
let message = createMessageUnder(elem, 'Hello, world!');
178178
document.body.append(message);
179179
setTimeout(() => message.remove(), 5000);
180180
```
181181
182182
```online
183-
Click the button to run it:
183+
Clicca il pulsante per eseguire:
184184
185-
<button id="coords-show-mark">Button with id="coords-show-mark", the message will appear under it</button>
185+
<button id="coords-show-mark">Pulsante con id="coords-show-mark", il messaggio apparirà sotto</button>
186186
```
187187
188-
The code can be modified to show the message at the left, right, below, apply CSS animations to "fade it in" and so on. That's easy, as we have all the coordinates and sizes of the element.
188+
Il codice può essere modificato per mostrare il messaggio a sinistra, a destra, sopra, per applicare animazioni CSS di dissolvenza e così via. Dal momento che disponiamo di tutte le coordinate e dimensioni dell'elemento è piuttosto semplice.
189189
190-
But note the important detail: when the page is scrolled, the message flows away from the button.
190+
Fate attenzione, tuttavia, ad un dettaglio importante: quando la pagina scorre, il pulsante si allontana dal messaggio.
191191
192-
The reason is obvious: the message element relies on `position:fixed`, so it remains at the same place of the window while the page scrolls away.
192+
Il motivo è ovvio: il messaggio si basa su `position:fixed`, quindi rimane nello stessa posizione relativamente alla finestra mentre la pagina scorre via.
193193
194-
To change that, we need to use document-based coordinates and `position:absolute`.
194+
Per cambiare questo comportamento, dobbiamo usare coordinate relative al documento e `position:absolute`.
195195
196-
## Document coordinates [#getCoords]
196+
## Coordinate relative al documento [#getCoords]
197197
198-
Document-relative coordinates start from the upper-left corner of the document, not the window.
198+
Le coordinate relative al documento hanno come riferimento l'angolo superiore sinistro del documento, non della finestra.
199199
200-
In CSS, window coordinates correspond to `position:fixed`, while document coordinates are similar to `position:absolute` on top.
200+
Nei CSS, le coordinate relative alla finestra corrispondono a `position:fixed`, mentre le coordinate relative al documento sono assimilabili a `position:absolute` riferito alla radice del documento.
201201
202202
We can use `position:absolute` and `top/left` to put something at a certain place of the document, so that it remains there during a page scroll. But we need the right coordinates first.
203203
@@ -245,11 +245,11 @@ function createMessageUnder(elem, html) {
245245
246246
## Riepilogo
247247
248-
Any point on the page has coordinates:
248+
Ogni punto sulla pagina ha delle coordinate:
249249
250-
1. Relative to the window -- `elem.getBoundingClientRect()`.
251-
2. Relative to the document -- `elem.getBoundingClientRect()` plus the current page scroll.
250+
1. relative alla finestra -- `elem.getBoundingClientRect()`.
251+
2. relative al documento -- `elem.getBoundingClientRect()` più lo scorrimento corrente di pagina.
252252
253-
Window coordinates are great to use with `position:fixed`, and document coordinates do well with `position:absolute`.
253+
Le coordinate relative alla finestra sono ottime per un utilizzo con `position:fixed` e le coordinate relative al documento vanno bene con `position:absolute`.
254254
255-
Both coordinate systems have their pros and cons; there are times we need one or the other one, just like CSS `position` `absolute` and `fixed`.
255+
Entrambi i sistemi di coordinate hanno i loro vantaggi e svantaggi; ci sono circostanze in cui abbiamo bisogno dell'uno o dell'altro, proprio come per la proprietà CSS `position` `absolute` e `fixed`.

0 commit comments

Comments
 (0)