You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most of time we need coordinates in order to position something.
147
+
La maggior parte delle volte abbiamo bisogno delle coordinate per posizionare qualcosa.
148
148
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`).
150
150
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`:
152
152
153
153
```js
154
154
let elem = document.getElementById("coords-show-mark");
@@ -172,32 +172,32 @@ function createMessageUnder(elem, html) {
172
172
return message;
173
173
}
174
174
175
-
// Usage:
176
-
// add it for 5 seconds in the document
175
+
// Esempio d'uso:
176
+
// aggiunge il messaggio al documento per 5 secondi
177
177
let message = createMessageUnder(elem, 'Hello, world!');
178
178
document.body.append(message);
179
179
setTimeout(() => message.remove(), 5000);
180
180
```
181
181
182
182
```online
183
-
Click the button to run it:
183
+
Clicca il pulsante per eseguire:
184
184
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>
186
186
```
187
187
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.
189
189
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.
191
191
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.
193
193
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`.
195
195
196
-
## Document coordinates [#getCoords]
196
+
## Coordinate relative al documento [#getCoords]
197
197
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.
199
199
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.
201
201
202
202
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.
203
203
@@ -245,11 +245,11 @@ function createMessageUnder(elem, html) {
245
245
246
246
## Riepilogo
247
247
248
-
Any point on the page has coordinates:
248
+
Ogni punto sulla pagina ha delle coordinate:
249
249
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.
252
252
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`.
254
254
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