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);