UNPKG

util-helpers

Version:

一个基于业务场景的工具方法库

27 lines (25 loc) 882 B
function injectStyle(css, options) { var _a = options || {}, _b = _a.container, container = _b === void 0 ? document.head || document.getElementsByTagName('head')[0] || document.body : _b, _c = _a.insertAt, insertAt = _c === void 0 ? 'top' : _c, onBefore = _a.onBefore; var style = document.createElement('style'); if (style.styleSheet) { style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } if (typeof onBefore === 'function') { onBefore(style); } var atTop = insertAt === 'top'; if (atTop && container.prepend) { container.prepend(style); } else if (atTop && container.firstChild) { container.insertBefore(style, container.firstChild); } else { container.appendChild(style); } return style; } export { injectStyle as default };