-
Notifications
You must be signed in to change notification settings - Fork 57
Element size and scrolling #279
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
longo-andrea
merged 16 commits into
javascript-tutorial:master
from
marcellosurdi:article/size-and-scroll
Apr 5, 2021
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9396e46
Update 2-ui\1-document\09-size-and-scroll\article.md
marcellosurdi c32a903
Merge branch 'article/size-and-scroll' of https://github.com/marcello…
marcellosurdi 53119a5
Update 2-ui\1-document\09-size-and-scroll\article.md
marcellosurdi 111445a
Update 2-ui\1-document\09-size-and-scroll\article.md
marcellosurdi 58fe280
Update 2-ui\1-document\09-size-and-scroll\article.md
marcellosurdi 7a858a8
Update 2-ui\1-document\09-size-and-scroll\article.md
marcellosurdi 553dbfc
Update 2-ui\1-document\09-size-and-scroll\article.md
marcellosurdi 516abff
Update 2-ui\1-document\09-size-and-scroll\article.md
marcellosurdi 7413592
Update 2-ui\1-document\09-size-and-scroll\tasks
marcellosurdi 65c5f95
Update 2-ui\1-document\09-size-and-scroll\tasks
marcellosurdi 42675cf
Update 2-ui\1-document\09-size-and-scroll\tasks
marcellosurdi 7a50345
Update 2-ui\1-document\09-size-and-scroll\tasks
marcellosurdi a317465
Update 2-ui\1-document\09-size-and-scroll\tasks
marcellosurdi c62a954
Review 2-ui\1-document\09-size-and-scroll
marcellosurdi 2281607
Apply suggestions from code review
marcellosurdi 5657400
Apply suggestions from code review (2)
marcellosurdi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
2-ui/1-document/09-size-and-scroll/1-get-scroll-height-bottom/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
The solution is: | ||
La soluzione è: | ||
|
||
```js | ||
let scrollBottom = elem.scrollHeight - elem.scrollTop - elem.clientHeight; | ||
``` | ||
|
||
In other words: (full height) minus (scrolled out top part) minus (visible part) -- that's exactly the scrolled out bottom part. | ||
In altre parole: (altezza totale) meno (misura dello scorrimento dall'alto) meno (altezza dell'area di scorrimento visibile). Il risultato è esattamente la misura della parte inferiore che resta da scorrere. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
2-ui/1-document/09-size-and-scroll/2-scrollbar-width/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 14 additions & 14 deletions
28
2-ui/1-document/09-size-and-scroll/4-put-ball-in-center/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,19 +2,19 @@ importance: 5 | |||||
|
||||||
--- | ||||||
|
||||||
# Place the ball in the field center | ||||||
# Posiziona la palla al centro del campo | ||||||
|
||||||
Here's how the source document looks: | ||||||
Ecco come si presenta il documento di partenza: | ||||||
|
||||||
[iframe src="source" edit link height=180] | ||||||
|
||||||
What are coordinates of the field center? | ||||||
Quali sono le coordinate del centro del campo? | ||||||
|
||||||
Calculate them and use to place the ball into the center of the green field: | ||||||
Calcolale e usale per posizionare la palla al centro del campo verde: | ||||||
|
||||||
[iframe src="solution" height=180] | ||||||
|
||||||
- The element should be moved by JavaScript, not CSS. | ||||||
- The code should work with any ball size (`10`, `20`, `30` pixels) and any field size, not be bound to the given values. | ||||||
- L'elemento dovrebbe essere spostato con JavaScript, non con i CSS. | ||||||
- Il codice dovrebbe funzionare anche con una dimensione della palla differente (`10`, `20`, `30` pixel) e qualunque dimensione del campo: non dovrebbe essere legato a valori noti. | ||||||
|
||||||
P.S. Sure, centering could be done with CSS, but here we want exactly JavaScript. Further we'll meet other topics and more complex situations when JavaScript must be used. Here we do a "warm-up". | ||||||
P.S. Certamente, il posizionamento al centro potrebbe essere ottenuto con i CSS, ma qui vi chiediamo di farlo proprio con JavaScript. Più avanti incontreremo altri casi e situazioni più complesse in cui JavaScript è l'unica alternativa. Ora ci stiamo solo "scaldando". | ||||||
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.
Suggested change
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. Mmm credo che di averlo sempre trovato con l'articolo in italiano, io lo lascerei così |
10 changes: 5 additions & 5 deletions
10
2-ui/1-document/09-size-and-scroll/6-width-vs-clientwidth/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Differences: | ||
Differenze: | ||
|
||
1. `clientWidth` is numeric, while `getComputedStyle(elem).width` returns a string with `px` at the end. | ||
2. `getComputedStyle` may return non-numeric width like `"auto"` for an inline element. | ||
3. `clientWidth` is the inner content area of the element plus paddings, while CSS width (with standard `box-sizing`) is the inner content area *without paddings*. | ||
4. If there's a scrollbar and the browser reserves the space for it, some browser substract that space from CSS width (cause it's not available for content any more), and some do not. The `clientWidth` property is always the same: scrollbar size is substracted if reserved. | ||
1. `clientWidth` è un valore numerico, `getComputedStyle(elem).width` invece restituisce una stringa con `px` alla fine. | ||
2. `getComputedStyle` può restituire una larghezza non numerica come `"auto"` per un elemento inline. | ||
3. `clientWidth` è l'area del contenuto interna di un elemento più il padding, mentre la proprietà width dei CSS (con il valore predefinito di `box-sizing`) è l'area del contenuto interna *senza il padding*. | ||
4. Se c'è una barra di scorrimento ed il browser le riserva uno spazio, alcuni browser sottraggono quello spazio alla larghezza impostata tramite CSS (perché non è più disponibile per i contenuti), e altri invece no. La proprietà `clientWidth` è sempre la stessa: se la barra di scorrimento ha uno spazio riservato viene sottratto all'area del contenuto. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm credo che di averlo sempre trovato con l'articolo in italiano, io lo lascerei così