From 5d01b91581fa7ee2530b13cef54d7456bfcb0d15 Mon Sep 17 00:00:00 2001 From: "ran.luo" Date: Wed, 30 Aug 2017 14:25:41 +0800 Subject: [PATCH] bugfix: fix the problem that image adapting in android device dint work --- dist/vue-img.es6.js | 7 ++++++- dist/vue-img.js | 7 ++++++- src/utils.js | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/dist/vue-img.es6.js b/dist/vue-img.es6.js index 834f48a..34e80db 100644 --- a/dist/vue-img.es6.js +++ b/dist/vue-img.es6.js @@ -32,10 +32,13 @@ const setAttr = (el, src, tag) => { const resize = (size) => { let viewWidth; + const dpr = window.devicePixelRatio; + const dataDpr = document.documentElement.getAttribute('data-dpr'); + const ratio = dataDpr ? (dpr / dataDpr) : dpr; + try { viewWidth = +(html.getAttribute('style').match(/(\d+)/) || [])[1]; } catch(e) { - const dpr = window.devicePixelRatio; const w = html.offsetWidth; if (w / dpr > 540) { viewWidth = 540 * dpr / 10; @@ -44,6 +47,8 @@ const resize = (size) => { } } + viewWidth = viewWidth * ratio; + if (Number(viewWidth) >= 0 && typeof viewWidth === 'number') { return (size * viewWidth) / 75 // 75 is the 1/10 iphone6 deivce width pixel } else { diff --git a/dist/vue-img.js b/dist/vue-img.js index 1762d70..392e0d6 100644 --- a/dist/vue-img.js +++ b/dist/vue-img.js @@ -42,10 +42,13 @@ var setAttr = function (el, src, tag) { var resize = function (size) { var viewWidth; + var dpr = window.devicePixelRatio; + var dataDpr = document.documentElement.getAttribute('data-dpr'); + var ratio = dataDpr ? (dpr / dataDpr) : dpr; + try { viewWidth = +(html.getAttribute('style').match(/(\d+)/) || [])[1]; } catch(e) { - var dpr = window.devicePixelRatio; var w = html.offsetWidth; if (w / dpr > 540) { viewWidth = 540 * dpr / 10; @@ -54,6 +57,8 @@ var resize = function (size) { } } + viewWidth = viewWidth * ratio; + if (Number(viewWidth) >= 0 && typeof viewWidth === 'number') { return (size * viewWidth) / 75 // 75 is the 1/10 iphone6 deivce width pixel } else { diff --git a/src/utils.js b/src/utils.js index 771ea41..ce77c9b 100644 --- a/src/utils.js +++ b/src/utils.js @@ -19,10 +19,13 @@ export const setAttr = (el, src, tag) => { export const resize = (size) => { let viewWidth + const dpr = window.devicePixelRatio + const dataDpr = document.documentElement.getAttribute('data-dpr') + const ratio = dataDpr ? (dpr / dataDpr) : dpr + try { viewWidth = +(html.getAttribute('style').match(/(\d+)/) || [])[1] } catch(e) { - const dpr = window.devicePixelRatio const w = html.offsetWidth if (w / dpr > 540) { viewWidth = 540 * dpr / 10 @@ -31,6 +34,8 @@ export const resize = (size) => { } } + viewWidth = viewWidth * ratio + if (Number(viewWidth) >= 0 && typeof viewWidth === 'number') { return (size * viewWidth) / 75 // 75 is the 1/10 iphone6 deivce width pixel } else {