| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| 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. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| Expand Up | @@ -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". | ||||||
|
Comment thread
Copy link
Copy Markdown
Contributor
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityMmm credo che di averlo sempre trovato con l'articolo in italiano, io lo lascerei così
Sorry, something went wrong.
All reactions
|
||||||
| 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. |
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualitySorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityMmm credo che di averlo sempre trovato con l'articolo in italiano, io lo lascerei così
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.