Skip to content

Commit

Permalink
bugfix: fix the problem that image adapting in android device dint work
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs committed Aug 30, 2017
1 parent 11143b0 commit 5d01b91
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion dist/vue-img.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion dist/vue-img.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 5d01b91

Please sign in to comment.