Example 1:
- There is a newly created element with
display: inline-block
.- We measure its width using the
offsetWidth
property.- Change its color.
- And, suddenly, in Google Chrome for Mobile, after a color change, the width of the element increases dramatically, ceasing to correspond to that measured by only two lines above!
Show code
<!DOCTYPE html> <html> <head> <meta http-equiv = "content-type" content = "text/html; charset=utf-8" /> <title> Font boosting Google Chrome for Mobile</title> <script type = "text/javascript"> window.onload = function () { var spnSpan1 = document.getElementById ("span-1"); alert (" : "+ spnSpan1.offsetWidth +"px"); //59px spnSpan1.style.color = "red"; alert (" : "+ spnSpan1.offsetWidth +"px"); //186px (WTF?!) } </script> </head> <body> <p> <span id = "span-1" style = "display: inline-block;"></span> </p> <!-- . , . --> <p> abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc </p> </body> </html>
See an example on-line .
')
(To view examples from this article, use Google Chrome for Mobile or regular Google Chrome in smartphone emulation mode , for example, Apple iPhone 5 or Samsung Galaxy Note II).
offsetWidth
.display: inline-block
happens not just after reflow of the page, but after reflow and changing some property of the element itself (for example, color).Example 2:
There are 4 elements, the first three of which are givendisplay: inline-block
, and the 4th is not. As a result, for the 4th element, the size increases immediately after the page loads, and for the 1-3 elements - only after changing their color.Show code
<!DOCTYPE html> <html> <head> <meta http-equiv = "content-type" content = "text/html; charset=utf-8" /> <title> Font boosting Google Chrome for Mobile</title> <script type = "text/javascript"> window.onload = function () { /* */ var spnSpan1 = document.getElementById ("span-1"); var spnSpan2 = document.getElementById ("span-2"); var spnSpan3 = document.getElementById ("span-3"); var btnGo = document.getElementById ("btnGo"); /* , */ btnGo.onclick = function () { spnSpan1.style.color = "red"; spnSpan2.style.color = "red"; spnSpan3.style.color = "red"; } } </script> </head> <body> <div> <input type = "button" id = "btnGo" value = " !" /> <!-- "display: inline-block", , ! --> <p> <span id = "span-1" style = "display: inline-block;"> 1</span> </p> <p > <span id = "span-2" style = "display: inline-block;"> 2</span> </p> <p> <span id = "span-3" style = "display: inline-block;"> 3</span> </p> <!-- "display: inline-block", --> <p> <span id = "span-4"> 4</span> </p> <!-- . , . --> <p> abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc </p> </div> </body> </html>
See an example on-line .
offsetWidth
newly created element, we get the value before font boosting.offsetWidth
increases, becoming noticeably larger than that measured by two lines above. <meta name = "viewport" content = "width=device-width, initial-scale=1">
Example 3Show code
<!DOCTYPE html> <html> <head> <meta http-equiv = "content-type" content = "text/html; charset=utf-8" /> <!-- --> <meta name = "viewport" content = "width=device-width, initial-scale=1"> <title>â„–1 Font boosting Google Chrome for Mobile</title> <script type = "text/javascript"> window.onload = function () { var spnSpan1 = document.getElementById ("span-1"); /* , font boosting , . */ alert (" : "+ spnSpan1.offsetWidth +"px"); //186px spnSpan1.style.color = "red"; alert (" : "+ spnSpan1.offsetWidth +"px"); //186px } </script> </head> <body> <p> <span id = "span-1" style = "display: inline-block;"></span> </p> <p> abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc </p> </body> </html>
See an example on-line .
document.body.offsetWidth
.display: inline-block
, then also change its color and then return it.Example 4Show code
<!DOCTYPE html> <html> <head> <meta http-equiv = "content-type" content = "text/html; charset=utf-8" /> <title>â„–2 Font boosting Google Chrome for Mobile</title> <script type = "text/javascript"> window.onload = function () { var spnSpan1 = document.getElementById ("span-1"); /* font boosting . */ doReflow (); doFontBoosting (spnSpan1); /* , . */ alert (" : "+ spnSpan1.offsetWidth +"px"); //186px spnSpan1.style.color = "red"; alert (" : "+ spnSpan1.offsetWidth +"px"); //186px } function doReflow () { document.body.offsetWidth; } function doFontBoosting (elElement) { var strColor = elElement.style.color; elElement.style.color = (strColor == "red" ? "blue" : "red"); elElement.style.color = strColor; } </script> </head> <body> <p> <span id = "span-1" style = "display: inline-block;"></span> </p> <p> abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc </p> </body> </html>
See an example on-line .
Source: https://habr.com/ru/post/214559/
All Articles