Skip to content

Commit 19d6698

Browse files
gabrielloebrodneyrehm
authored andcommitted
fix(polyfill): allow appending generated CSS to body
1 parent 457e53a commit 19d6698

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

Readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ viewportUnitsBuggyfill.init({refreshDebounceWait: 250});
9999
//
100100
viewportUnitsBuggyfill.init({hacks: window.viewportUnitsBuggyfillHacks});
101101

102+
// append the patched stylesheet to body instead of head
103+
viewportUnitsBuggyfill.init({appendToBody: true});
104+
102105
// update internal declarations cache and recalculate pixel styles
103106
// this is handy when you add styles after .init() was run
104107
viewportUnitsBuggyfill.refresh();

index.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</style>
2424
</head>
2525
<body>
26-
26+
2727
<p><strong>Note:</strong> this script will only work with browsers that have buggy implementations of viewport units and will not polyfill viewport units in older browsers (e.g. IE &lt;= 8)</p>
2828
<script src="viewport-units-buggyfill.js"></script>
2929
<script src="viewport-units-buggyfill.hacks.js"></script>
@@ -33,7 +33,14 @@
3333
// milliseconds to delay between updates of viewport-units
3434
// caused by orientationchange, pageshow, resize events
3535
refreshDebounceWait: 250,
36-
hacks: window.viewportUnitsBuggyfillHacks
36+
hacks: window.viewportUnitsBuggyfillHacks,
37+
// append to body
38+
appendToBody: true
3739
});</script>
40+
<style>
41+
.css-in-body {
42+
width: 25vw;
43+
}
44+
</style>
3845
</body>
3946
</html>

viewport-units-buggyfill.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
initialized = true;
162162
styleNode = document.createElement('style');
163163
styleNode.id = 'patched-viewport';
164-
document.head.appendChild(styleNode);
164+
document[options.appendToBody ? 'body' : 'head'].appendChild(styleNode);
165165

166166
// Issue #6: Cross Origin Stylesheets are not accessible through CSSOM,
167167
// therefore download and inject them as <style> to circumvent SOP.

0 commit comments

Comments
 (0)