Skip to content

Instantly share code, notes, and snippets.

@elanpang
Created October 30, 2018 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elanpang/fa2cc7d97c36c28eca2b27be01c432c4 to your computer and use it in GitHub Desktop.
Save elanpang/fa2cc7d97c36c28eca2b27be01c432c4 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/xovijac
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
//保留两位小数
const calcScreenRealSize=(h,w,rl)=>{
//屏幕比例
const hFactor=h;
const wFactor=w;
//对角线长
const lengthReal=rl;
//实际屏幕长宽和面积
let hReal=0;
let wReal=0;
let areaReal=0;
wReal=Math.sqrt(lengthReal*lengthReal/(Math.pow(hFactor/wFactor,2)+1));
hReal=hFactor/wFactor * wReal;
areaReal=wReal*hReal;
return {
rw:wReal.toFixed(2),
rh:hReal.toFixed(2),
rArea:areaReal.toFixed(2),
};
};
const x8Max=calcScreenRealSize(18.7,9,7.12);
console.log(`x8Max w:${x8Max.rw} h:${x8Max.rh} area:${x8Max.rArea}`);
const x2=calcScreenRealSize(16,9,7);
console.log(`x2 w:${x2.rw} h:${x2.rh} area:${x2.rArea}`);
</script>
<script id="jsbin-source-javascript" type="text/javascript">
//保留两位小数
const calcScreenRealSize=(h,w,rl)=>{
//屏幕比例
const hFactor=h;
const wFactor=w;
//对角线长
const lengthReal=rl;
//实际屏幕长宽和面积
let hReal=0;
let wReal=0;
let areaReal=0;
wReal=Math.sqrt(lengthReal*lengthReal/(Math.pow(hFactor/wFactor,2)+1));
hReal=hFactor/wFactor * wReal;
areaReal=wReal*hReal;
return {
rw:wReal.toFixed(2),
rh:hReal.toFixed(2),
rArea:areaReal.toFixed(2),
};
};
const x8Max=calcScreenRealSize(18.7,9,7.12);
console.log(`x8Max w:${x8Max.rw} h:${x8Max.rh} area:${x8Max.rArea}`);
const x2=calcScreenRealSize(16,9,7);
console.log(`x2 w:${x2.rw} h:${x2.rh} area:${x2.rArea}`);</script></body>
</html>
//保留两位小数
const calcScreenRealSize=(h,w,rl)=>{
//屏幕比例
const hFactor=h;
const wFactor=w;
//对角线长
const lengthReal=rl;
//实际屏幕长宽和面积
let hReal=0;
let wReal=0;
let areaReal=0;
wReal=Math.sqrt(lengthReal*lengthReal/(Math.pow(hFactor/wFactor,2)+1));
hReal=hFactor/wFactor * wReal;
areaReal=wReal*hReal;
return {
rw:wReal.toFixed(2),
rh:hReal.toFixed(2),
rArea:areaReal.toFixed(2),
};
};
const x8Max=calcScreenRealSize(18.7,9,7.12);
console.log(`x8Max w:${x8Max.rw} h:${x8Max.rh} area:${x8Max.rArea}`);
const x2=calcScreenRealSize(16,9,7);
console.log(`x2 w:${x2.rw} h:${x2.rh} area:${x2.rArea}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment