From 5198bde7eb749b85b3caf0c6cb0ff2c9cdd42862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E6=98=8E=E7=A4=BC?= Date: Fri, 21 Jul 2017 10:31:52 +0800 Subject: [PATCH] Update rem2px.js --- rem2px.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rem2px.js b/rem2px.js index 183edd9..18b1aff 100644 --- a/rem2px.js +++ b/rem2px.js @@ -1,9 +1,11 @@ function adapt(designWidth, rem2px){ - var d = window.document.createElement('div'); + var doc = window.document; + var d = doc.createElement('div'); d.style.width = '1rem'; d.style.display = "none"; - var head = window.document.getElementsByTagName('head')[0]; - head.appendChild(d); + var head = doc.getElementsByTagName('head')[0]; + var body = doc.body; + body.appendChild(d); var defaultFontSize = parseFloat(window.getComputedStyle(d, null).getPropertyValue('width')); // d.remove(); // document.documentElement.style.fontSize = window.innerWidth / designWidth * rem2px / defaultFontSize * 100 + '%'; @@ -14,4 +16,4 @@ function adapt(designWidth, rem2px){ head.appendChild(st); return defaultFontSize }; -var defaultFontSize = adapt(640, 100); \ No newline at end of file +var defaultFontSize = adapt(640, 100);