前端测试pad和pc

This commit is contained in:
2025-06-26 11:36:30 +08:00
parent dd144e6925
commit 6b1314d834

View File

@@ -19,13 +19,62 @@
<script type="text/javascript" src="__JS__/before-after.min.js"></script> <script type="text/javascript" src="__JS__/before-after.min.js"></script>
<script type="text/javascript" src="__JS__/large.js"></script> <script type="text/javascript" src="__JS__/large.js"></script>
<script type="text/javascript"> <script type="text/javascript">
function detectDeviceByResolution() {
// 获取屏幕信息
const screenWidth = window.screen.width;
const screenHeight = window.screen.height;
const aspectRatio = screenWidth / screenHeight;
const pixelDensity = window.devicePixelRatio || 1;
// 计算物理屏幕尺寸(对角线英寸数)
// 注意:此计算依赖浏览器提供准确的 devicePixelRatio
const diagonalPixels = Math.sqrt(
Math.pow(screenWidth, 2) + Math.pow(screenHeight, 2)
);
const diagonalInches = diagonalPixels / pixelDensity / 96;
// 设备类型判断阈值
const isTabletSize = diagonalInches >= 7 && diagonalInches <= 13;
const isLaptopSize = diagonalInches > 13 && diagonalInches <= 17;
const isDesktopSize = diagonalInches > 17;
// 常见平板分辨率模式(非绝对标准)
const isTabletResolution = (
(screenWidth >= 768 && screenWidth <= 1100 && aspectRatio <= 1.7) || // 竖屏或方屏平板
(screenHeight >= 768 && screenHeight <= 1100 && aspectRatio >= 1.5) // 横屏平板
);
// 常见PC/笔记本分辨率模式
const isPcResolution = (
(screenWidth >= 1280 && aspectRatio >= 1.6) || // 宽屏笔记本/桌面
(screenWidth >= 1920) // 高分辨率桌面
);
if (isTabletSize && isTabletResolution) {
return 'tablet';
} else if (isLaptopSize && isPcResolution) {
return 'laptop';
} else if (isDesktopSize && isPcResolution) {
return 'desktop';
} else {
return 'unknown';
}
}
$(window).ready(function () { $(window).ready(function () {
if ($(window).width() < 1024) { const deviceType = detectDeviceByResolution();
if (deviceType=='tablet') {
window.location.href = '?mtpl=1'; window.location.href = '?mtpl=1';
} }
}) })
// $(window).ready(function () {
// if ($(window).width() < 1024) {
// window.location.href = '?mtpl=1';
// }
// })
</script> </script>
</head> </head>
<body> <body>
{block name="header"} {block name="header"}
{include file="public/header"/} {include file="public/header"/}
@@ -36,4 +85,5 @@
{/block} {/block}
{block name="script"}{/block} {block name="script"}{/block}
</body> </body>
</html> </html>