지금 이 사용하고 있습니다.
function is_retina_device() {
return window.devicePixelRatio > 1;
}
그러나 it& # 39 의 단순한 빈곤으로써 나여야지 것이 더 철저한 검사가 있나요?
(W3.org) 에 따르면: >. Once upon a time, 웹킷 화면 해상도 필요한 것은 미디어 쿼리합니다 했다. 하지만 그들이 사용하는 대신 이미 표준화했습니다 해결안에서는 미디어 쿼리하지 거역하 - 웹킷 디바이스입니다 픽셀입니다 제거율.
[보기 전체 기사] (http://www.w3.org/blog/CSS/2012/06/14/unprefix-webkit-device-pixel-ratio/)
[해결안에서는 쿼리하지 미디어 붽뎄] (http://www.w3.org/TR/css3-mediaqueries/ # 해상도)
이후 '해결' 는 향후 let& # 39 의 첫 번째 감지, 그러므로 표준화했습니다 사용하는 향후 교정. # 39 만 감지할 수 있는지 알고 있기 때문에, 또한 I& m 전용 스케쳐내 높은 드프스 디바이스이거나 망막 (애플 전용) 장치, I& # 39, ve 추가되든지 둘 중 하나. 참고로, 결국 그냥 그냥 애플 감지 기능은 사용자 에이전트 스니핑 그러하매 can&, t be # 39 에 내놓는다. 참고: # 39, m '의' 기능을 사용하여 이레티나 I& 드프스 대신 모든 애플 기기를 갖고 있기 때문에 2 1.3 망막 2dppx.
function isHighDensity(){
return ((window.matchMedia && (window.matchMedia('only screen and (min-resolution: 124dpi), only screen and (min-resolution: 1.3dppx), only screen and (min-resolution: 48.8dpcm)').matches || window.matchMedia('only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen and (-o-min-device-pixel-ratio: 2.6/2), only screen and (min--moz-device-pixel-ratio: 1.3), only screen and (min-device-pixel-ratio: 1.3)').matches)) || (window.devicePixelRatio && window.devicePixelRatio > 1.3));
}
function isRetina(){
return ((window.matchMedia && (window.matchMedia('only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx), only screen and (min-resolution: 75.6dpcm)').matches || window.matchMedia('only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2/1), only screen and (min--moz-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2)').matches)) || (window.devicePixelRatio && window.devicePixelRatio >= 2)) && /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
}
스케쳐내 쉽게 사용할 수 있는 이미지가 레이나이스 또는 이 코드는 일반적인 응답 발견할 수 있다.
function isRetinaDisplay() {
if (window.matchMedia) {
var mq = window.matchMedia("only screen and (min--moz-device-pixel-ratio: 1.3), only screen and (-o-min-device-pixel-ratio: 2.6/2), only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen and (min-device-pixel-ratio: 1.3), only screen and (min-resolution: 1.3dppx)");
return (mq && mq.matches || (window.devicePixelRatio > 1));
}
}
사실 이 문제는 그냥 사용하여 코드 you& # 39 에 불과, re 완전히 오른쪽 신경습니까 경우 현대 브라우저. (참조: http://caniuse.com/ # 성과 = 데비스피스엘라티오)
현대의 모든 브라우저, 이전 버전의 브라우저를 너회의 낮은 해상도의 이미지를 할꺼이나 구현됩니까 약간만이라도 그냥 지냈다. # 39, 내가 don& 작성되지는 IE10 - t / 고해상도 레티나 표시하십시오 증가한 디바이스입니다. 또한, CSS, JavaScript 를 사용하는 것보다 더 이상한 것은 사용하고 체크인됩니다 네이티브 창 속성?
헥 데비스피스엘라티오 브라우저 지원) 은 물론이고, 것보다 더 나은 해결안에서는 사양명세. (참조: http://caniuse.com/ # 성과 = css 미디어 해결안에서는)
단 한가지 I& # 39 는 고해상도 이미지를 하는 함수 이름 변경, d, t # 39 로 로드하기에 doesn&, 기술적으로 짓궂군요 화면은 레티나. 사실 확인 할 수 있기 때문에, '정의되지 않은 > 너회가 don& # 39, 못할 정도였습니다. 1 '결과' 거짓 '.
function is_high_resolution_screen() {
return window.devicePixelRatio > 1;
}