Skip to content

zhangyu1818/dynamic-stylesheet

Repository files navigation

dynamic-stylesheet

npm-version codecov bundlesize-js-image

dynamic inject css with javascript.

Install

npm install dynamic-stylesheet
yarn add dynamic-stylesheet

Usage

import { injectCSS, updateCSS } from 'dynamic-stylesheet'

const styleText = ".container:before{ content:'before content' }"

// default insert to document.head
injectCSS(styleText)
// attach to element
injectCSS(styleText, { attachTo: document.body })

// updateCSS will use the same node with the same key
updateCSS(styleText, 'mark-key')

const updateStyleText = ".container:after{ content:'after content' }"

updateCSS(updateStyleText, 'mark-key')

License

MIT