Skip to content

Commit 67ccf23

Browse files
authored
Merge pull request #286 from marcellosurdi/article/coordinates
Coordinates
2 parents c5bcc3f + fc14465 commit 67ccf23

File tree

13 files changed

+160
-160
lines changed

13 files changed

+160
-160
lines changed

2-ui/1-document/11-coordinates/1-find-point-coordinates/solution.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Outer corners
1+
# Angoli esterni
22

3-
Outer corners are basically what we get from [elem.getBoundingClientRect()](https://developer.mozilla.org/en-US/docs/DOM/element.getBoundingClientRect).
3+
Gli angoli esterni sono fondamentalmente quello che otteniamo da [elem.getBoundingClientRect()](https://developer.mozilla.org/en-US/docs/DOM/element.getBoundingClientRect).
44

5-
Coordinates of the upper-left corner `answer1` and the bottom-right corner `answer2`:
5+
Le coordinate dell'angolo superiore sinistro `answer1` e quelle dell'angolo inferiore destro `answer2`:
66

77
```js
88
let coords = elem.getBoundingClientRect();
@@ -11,19 +11,19 @@ let answer1 = [coords.left, coords.top];
1111
let answer2 = [coords.right, coords.bottom];
1212
```
1313

14-
# Left-upper inner corner
14+
# Angolo interno superiore sinistro
1515

16-
That differs from the outer corner by the border width. A reliable way to get the distance is `clientLeft/clientTop`:
16+
Questo differisce dall'angolo esterno solo per la larghezza del bordo. Un modo affidabile per calcolare la distanza è `clientLeft/clientTop`:
1717

1818
```js
1919
let answer3 = [coords.left + field.clientLeft, coords.top + field.clientTop];
2020
```
2121

22-
# Right-bottom inner corner
22+
# Angolo interno inferiore destro
2323

24-
In our case we need to substract the border size from the outer coordinates.
24+
Nel nostro caso possiamo sottrarre la misura del bordo dalle coordinate esterne.
2525

26-
We could use CSS way:
26+
Potremmo utilizzare il valore CSS:
2727

2828
```js
2929
let answer4 = [
@@ -32,7 +32,7 @@ let answer4 = [
3232
];
3333
```
3434

35-
An alternative way would be to add `clientWidth/clientHeight` to coordinates of the left-upper corner. That's probably even better:
35+
Un'alternativa sarebbe aggiungere `clientWidth/clientHeight` alle coordinate dell'angolo interno superiore sinistro. Questa è probabilmente la soluzione migliore:
3636

3737
```js
3838
let answer4 = [

2-ui/1-document/11-coordinates/1-find-point-coordinates/solution.view/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
<meta charset="utf-8">
66
<link rel="stylesheet" href="index.css">
77
<script>
8-
document.onclick = function(e) { // shows click coordinates
8+
document.onclick = function(e) { // mostra le coordinate del click
99
coords.innerHTML = e.clientX + ':' + e.clientY;
1010
};
1111
</script>
1212
</head>
1313

1414
<body>
1515

16-
Click anywhere to get window coordinates.
17-
<br> That's for testing, to check the result you get by JavaScript.
16+
Clicca in un punto qualsiasi per ottenere le coordinate relative alla finestra.
17+
<br> Fatelo a scopo di test, per verificare il risultato che ottenete con JavaScript.
1818
<br>
19-
<div id="coords">(click coordinates show up here)</div>
19+
<div id="coords">(le coordinate del click vengono mostrate qui)</div>
2020

2121

2222
<div id="field">

2-ui/1-document/11-coordinates/1-find-point-coordinates/source.view/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
<meta charset="utf-8">
66
<link rel="stylesheet" href="index.css">
77
<script>
8-
document.onclick = function(e) { // shows click coordinates
8+
document.onclick = function(e) { // mostra le coordinate del click
99
coords.innerHTML = e.clientX + ':' + e.clientY;
1010
};
1111
</script>
1212
</head>
1313

1414
<body>
1515

16-
Click anywhere to get window coordinates.
17-
<br> That's for testing, to check the result you get by JavaScript.
16+
Clicca in un punto qualsiasi per ottenere le coordinate relative alla finestra.
17+
<br> Fatelo a scopo di test, per verificare il risultato che ottenete con JavaScript.
1818
<br>
19-
<div id="coords">(click coordinates show up here)</div>
19+
<div id="coords">(le coordinate del click vengono mostrate qui)</div>
2020

2121

2222
<div id="field">
@@ -32,7 +32,7 @@
3232

3333

3434
<script>
35-
// ...your code...
35+
// ...il tuo codice...
3636
</script>
3737

3838
</body>

2-ui/1-document/11-coordinates/1-find-point-coordinates/task.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ importance: 5
22

33
---
44

5-
# Find window coordinates of the field
5+
# Trovate le coordinate del campo relative alla finestra
66

7-
In the iframe below you can see a document with the green "field".
7+
Nell'iframe sotto potete osservare un documento con un "campo" verde.
88

9-
Use JavaScript to find window coordinates of corners pointed by with arrows.
9+
Usate JavaScript per trovare le coordinate relative alla finestra degli angoli indicati dalle frecce.
1010

11-
There's a small feature implemented in the document for convenience. A click at any place shows coordinates there.
11+
Per comodità è stata implementata una semplice funzionalità nel documento: un click in un punto qualsiasi mostrerà le coordinate.
1212

1313
[iframe border=1 height=360 src="source" link edit]
1414

15-
Your code should use DOM to get window coordinates of:
15+
Il vostro codice dovrebbe usare il DOM per ottenere le coordinate relative alla finestra di:
1616

17-
1. Upper-left, outer corner (that's simple).
18-
2. Bottom-right, outer corner (simple too).
19-
3. Upper-left, inner corner (a bit harder).
20-
4. Bottom-right, inner corner (there are several ways, choose one).
17+
1. angolo esterno superiore sinistro (è semplice).
18+
2. angolo esterno inferiore destro (semplice anche questo).
19+
3. angolo interno superiore sinistro (un po' più difficile).
20+
4. angolo interno inferiore destro (esistono vari modi, sceglietene uno).
2121

22-
The coordinates that you calculate should be the same as those returned by the mouse click.
22+
Le coordinate che calcolate dovrebbero essere le stesse di quelle mostrate al click del mouse.
2323

24-
P.S. The code should also work if the element has another size or border, not bound to any fixed values.
24+
P.S. Il codice dovrebbe funzionare anche se l'elemento ha un'altra dimensione o un altro bordo, non deve dipendere da valori fissi.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
In this task we only need to accurately calculate the coordinates. See the code for details.
1+
In questo esercizio dobbiamo solo calcolare accuratamente le coordinate. Guardate il codice per i dettagli.
22

3-
Please note: the elements must be in the document to read `offsetHeight` and other properties.
4-
A hidden (`display:none`) or out of the document element has no size.
3+
Nota bene: gli elementi devono essere visibili nel documento per leggere `offsetHeight` e le altre proprietà.
4+
Un elemento nascosto (`display:none`) o fuori dal documento non ha dimensioni.

2-ui/1-document/11-coordinates/2-position-at/solution.view/index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424

2525
<script>
2626
/**
27-
* Positions elem relative to anchor as said in position.
27+
* Posiziona elem relativamente a anchor come indicato in position.
2828
*
29-
* @param {Node} anchor Anchor element for positioning
30-
* @param {string} position One of: top/right/bottom
31-
* @param {Node} elem Element to position
29+
* @param {Node} anchor Elemento di riferimento per il posizionamento
30+
* @param {string} position Un valore tra: top/right/bottom
31+
* @param {Node} elem Elemento da posizionare
3232
*
33-
* Both elements: elem and anchor must be in the document
33+
* Entrambi gli elementi, elem e anchor, devono essere visibili nel documento
3434
*/
3535
function positionAt(anchor, position, elem) {
3636

@@ -55,10 +55,10 @@
5555

5656
}
5757

58-
/**
59-
* Shows a note with the given html at the given position
60-
* relative to the anchor element.
61-
*/
58+
/**
59+
* Mostra una nota con l'html passato come parametro nella posizione indicata
60+
* relativa all'elemento anchor.
61+
*/
6262
function showNote(anchor, position, html) {
6363

6464
let note = document.createElement('div');
@@ -69,7 +69,7 @@
6969
positionAt(anchor, position, note);
7070
}
7171

72-
// test it
72+
// prova
7373
let blockquote = document.querySelector('blockquote');
7474

7575
showNote(blockquote, "top", "note above");

2-ui/1-document/11-coordinates/2-position-at/source.view/index.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@
2424

2525
<script>
2626
/**
27-
* Positions elem relative to anchor as said in position.
27+
* Posiziona elem relativamente a anchor come indicato in position.
2828
*
29-
* @param {Node} anchor Anchor element for positioning
30-
* @param {string} position One of: top/right/bottom
31-
* @param {Node} elem Element to position
29+
* @param {Node} anchor Elemento di riferimento per il posizionamento
30+
* @param {string} position Un valore tra: top/right/bottom
31+
* @param {Node} elem Elemento da posizionare
3232
*
33-
* Both elements: elem and anchor must be in the document
33+
* Entrambi gli elementi, elem e anchor, devono essere visibili nel documento
3434
*/
3535
function positionAt(anchor, position, elem) {
3636
// ... your code ...
3737
}
3838

3939
/**
40-
* Shows a note with the given html at the given position
41-
* relative to the anchor element.
40+
* Mostra una nota con l'html passato come parametro nella posizione indicata
41+
* relativa all'elemento anchor.
4242
*/
4343
function showNote(anchor, position, html) {
4444

@@ -50,7 +50,7 @@
5050
positionAt(anchor, position, note);
5151
}
5252

53-
// test it
53+
// prova
5454
let blockquote = document.querySelector('blockquote');
5555

5656
showNote(blockquote, "top", "note above");

2-ui/1-document/11-coordinates/2-position-at/task.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ importance: 5
22

33
---
44

5-
# Show a note near the element
5+
# Mostrate una nota vicino l'elemento
66

7-
Create a function `positionAt(anchor, position, elem)` that positions `elem`, depending on `position` near `anchor` element.
7+
Create una funzione `positionAt(anchor, position, elem)` che posizioni `elem` vicino l'elemento `anchor` in base a `position`.
88

9-
The `position` must be a string with any one of 3 values:
10-
- `"top"` - position `elem` right above `anchor`
11-
- `"right"` - position `elem` immediately at the right of `anchor`
12-
- `"bottom"` - position `elem` right below `anchor`
9+
Il parametro `position` deve essere una stringa con uno dei 3 valori seguenti:
10+
- `"top"` - posiziona `elem` proprio sopra `anchor`
11+
- `"right"` - posiziona `elem` subito a destra di `anchor`
12+
- `"bottom"` - posiziona `elem` esattamente sotto `anchor`
1313

14-
It's used inside function `showNote(anchor, position, html)`, provided in the task source code, that creates a "note" element with given `html` and shows it at the given `position` near the `anchor`.
14+
Il codice che scriverete viene richiamato dalla funzione `showNote(anchor, position, html)`, che trovate nel codice sorgente dell'esercizio e che crea una nota con l'`html` passato come parametro e lo mostra nella posizione assegnata `position` vicino all'elemento `anchor`.
1515

16-
Here's the demo of notes:
16+
Ecco un esempio:
1717

1818
[iframe src="solution" height="350" border="1" link]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The solution is actually pretty simple:
1+
La soluzione è in realtà piuttosto semplice:
22

3-
- Use `position:absolute` in CSS instead of `position:fixed` for `.note`.
4-
- Use the function [getCoords()](info:coordinates#getCoords) from the chapter <info:coordinates> to get document-relative coordinates.
3+
- Utilizzate `position:absolute` nel file CSS invece di `position:fixed` per `.note`.
4+
- Utilizzate la funzione [getCoords()](info:coordinates#getCoords) della sezione <info:coordinates> per ottenere le coordinate relative al documento.

2-ui/1-document/11-coordinates/3-position-at-absolute/solution.view/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
positionAt(anchor, position, note);
6767
}
6868

69-
// test it
69+
// prova
7070
let blockquote = document.querySelector('blockquote');
7171

7272
showNote(blockquote, "top", "note above");

2-ui/1-document/11-coordinates/3-position-at-absolute/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ importance: 5
22

33
---
44

5-
# Show a note near the element (absolute)
5+
# Mostrate una nota vicino l'elemento (position:absolute)
66

7-
Modify the solution of the [previous task](info:task/position-at) so that the note uses `position:absolute` instead of `position:fixed`.
7+
Modificate la soluzione dell'[esercizio precedente](info:task/position-at) affinché la nota utilizzi `position:absolute` invece di `position:fixed`.
88

9-
That will prevent its "runaway" from the element when the page scrolls.
9+
In questo modo eviteremo che si allontani dall'elemento quando la pagina scorre.
1010

11-
Take the solution of that task as a starting point. To test the scroll, add the style `<body style="height: 2000px">`.
11+
Prendete la soluzione dell'esecizio precedente come punto di partenza. Per testare lo scorrimento aggiungete lo stile `<body style="height: 2000px">`.

2-ui/1-document/11-coordinates/4-position-inside-absolute/task.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ importance: 5
22

33
---
44

5-
# Position the note inside (absolute)
5+
# Posizionate la nota all'interno (position:absolute)
66

7-
Extend the previous task <info:task/position-at-absolute>: teach the function `positionAt(anchor, position, elem)` to insert `elem` inside the `anchor`.
7+
Estendete l'esercizio precedente <info:task/position-at-absolute>: fate in modo che la funzione `positionAt(anchor, position, elem)` inserisca `elem` all'interno di `anchor`.
88

9-
New values for `position`:
9+
Nuovi valori per `position`:
1010

11-
- `top-out`, `right-out`, `bottom-out` -- work the same as before, they insert the `elem` over/right/under `anchor`.
12-
- `top-in`, `right-in`, `bottom-in` -- insert `elem` inside the `anchor`: stick it to the upper/right/bottom edge.
11+
- `top-out`, `right-out`, `bottom-out` -- funzionano come prima, inseriscono `elem` sopra/a destra/sotto `anchor`.
12+
- `top-in`, `right-in`, `bottom-in` -- inseriscono `elem` all'interno di `anchor`: posizionandolo nel bordo superiore/a destra/inferiore.
1313

14-
For instance:
14+
Per esempio:
1515

1616
```js
17-
// shows the note above blockquote
17+
// mostra la nota sopra blockquote
1818
positionAt(blockquote, "top-out", note);
1919

20-
// shows the note inside blockquote, at the top
20+
// mostra la nota all'interno di blockquote, nel bordo superiore
2121
positionAt(blockquote, "top-in", note);
2222
```
2323

24-
The result:
24+
Ecco il risultato:
2525

2626
[iframe src="solution" height="310" border="1" link]
2727

28-
As the source code, take the solution of the task <info:task/position-at-absolute>.
28+
Prendete la soluzione dell'esercizio <info:task/position-at-absolute> come codice sorgente.

0 commit comments

Comments
 (0)