Answer the question
In order to leave comments, you need to log in
How to determine phone screen diagonal in inches using javascript?
How to determine phone screen diagonal in javascript?
Answer the question
In order to leave comments, you need to log in
Pixels:
function getPxDiag(){
var scW = screen.width, scH = screen.height;
//return Math.hypot(scW, scH) - не работает в IE
return Math.sqrt( Math.pow(scW, 2) + Math.pow(scH, 2) );
}
//Общая формула: PIXEL = INCHES / (1 / DPI);
function getInchDiag(){
var DPI = inch.offsetWidth;
return getPxDiag() * (1/DPI);
}
alert( getInchDiag() );
1in
, accordingly, has a width less than a real inch. www.quirksmode.org/mobile/viewports.html ( translation )
tl;dr
use device-width and device-height in css
or screen.width and screen.height in js
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question