Last active
April 2, 2018 08:32
-
-
Save teamrun/94ddd2e4ff33722d969bd9e83b3dbafe to your computer and use it in GitHub Desktop.
计算屏幕宽高厘米值 get width and height of screen in cm
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
| function getScreenWidthHeight(inch, wRatio = 16, hRatio = 9) { | |
| let diagonalCm = inch * 2.54; | |
| let diagonalRatio = wRatio * wRatio + hRatio * hRatio; | |
| let oneItem = Math.sqrt(diagonalCm * diagonalCm / diagonalRatio); | |
| return { | |
| width: Number((wRatio * oneItem).toFixed(2)), | |
| height: Number((hRatio * oneItem).toFixed(2)), | |
| }; | |
| } | |
| // 55寸电视宽高 16:9 | |
| getScreenWidthHeight(55); //w: 121.76, h: 68.49 | |
| // 150寸幕布宽高 4:3 | |
| getScreenWidthHeight(150, 4, 3); //w: 304.8, h: 228.6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment