이 글에서는 브라우저 확대/축소 감지를 위한 js 코드를 주로 소개합니다. 필요한 친구들이 참고할 수 있습니다.
테스트 코드
효과:
크롬:
window.devicePixelRatio : 2 (准确) screen.deviceXDPI / screen.logicalXDPI : NaN window.outerWidth / window.innerWidth : 2 document.documentElement.offsetHeight / window.innerHeight : 0.020618556701030927 (有相关性) window.top.outerWidth / window.top.innerWidth : 2
ff:
window.devicePixelRatio : 1.5 (准确) screen.deviceXDPI / screen.logicalXDPI : NaN window.outerWidth / window.innerWidth : 1.0114583333333333 document.documentElement.offsetHeight / window.innerHeight : 0.023391812865497075 (有相关性) window.top.outerWidth / window.top.innerWidth : 1.0114583333333333
ie 8:
window.devicePixelRatio : undefined screen.deviceXDPI / screen.logicalXDPI : 1.5416666666666667 (大致准确) window.outerWidth / window.innerWidth : NaN document.documentElement.offsetHeight / window.innerHeight : NaN window.top.outerWidth / window.top.innerWidth : NaN
ie11:
window.devicePixelRatio : 1.5 (准确) screen.deviceXDPI / screen.logicalXDPI : 1.5window.outerWidth / window.innerWidth : 1.0084033613445377document.documentElement.offsetHeight / window.innerHeight : 0.02203856749311295 (有相关性)window.top.outerWidth / window.top.innerWidth : 1.0084033613445377
ie10:
window.devicePixelRatio : undefined screen.deviceXDPI / screen.logicalXDPI : 1.5 (准确) window.outerWidth / window.innerWidth : 1.0084033613445377 document.documentElement.offsetHeight / window.innerHeight : 1 window.top.outerWidth / window.top.innerWidth : 1.0084033613445377
ie9:
window.devicePixelRatio : undefined screen.deviceXDPI / screen.logicalXDPI : 1.5 (准确) window.outerWidth / window.innerWidth : 1.0084033613445377 document.documentElement.offsetHeight / window.innerHeight : 1 window.top.outerWidth / window.top.innerWidth : 1.0084033613445377
360 6.3(전혀 응답 없음):
window.devicePixelRatio : undefined screen.deviceXDPI / screen.logicalXDPI : 1 window.outerWidth / window.innerWidth : NaN document.documentElement.offsetHeight / window.innerHeight : NaN window.top.outerWidth / window.top.innerWidth : NaN
360 고속 브라우저:
window.devicePixelRatio : 1 screen.deviceXDPI / screen.logicalXDPI : NaN window.outerWidth / window.innerWidth : 1.5 document.documentElement.offsetHeight / window.innerHeight : 0.015267175572519083 window.top.outerWidth / window.top.innerWidth : 1.5(准确)
Sogou 고속 브라우저(완료 무응답):
window.devicePixelRatio : undefined screen.deviceXDPI / screen.logicalXDPI : 1 window.outerWidth / window.innerWidth : NaN document.documentElement.offsetHeight / window.innerHeight : NaN window.top.outerWidth / window.top.innerWidth : NaN
Taobao 브라우저:
window.devicePixelRatio : 1 screen.deviceXDPI / screen.logicalXDPI : NaN window.outerWidth / window.innerWidth : 2.0710059171597632 (大致准确) document.documentElement.offsetHeight / window.innerHeight : 0.022988505747126436 window.top.outerWidth / window.top.innerWidth : 2.0710059171597632
위는 이 장의 전체 내용입니다. 더 많은 관련 튜토리얼을 보려면 자바스크립트 비디오 튜토리얼!