获取设备像素比及屏幕宽高,便于@media机型适配

41 阅读1分钟
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
		
		var screenwidth=window.screen.width;
		var screenheight=window.screen.height;
      	document.write(`
		  设备像素比:${window.devicePixelRatio},
	      屏幕的宽度为:${screenwidth},
	      屏幕的高度为:${screenheight}
	    `)
		</script>
	</body>
</html>