Skip to content

Instantly share code, notes, and snippets.

@daformat
Last active July 12, 2022 12:05
Show Gist options
  • Save daformat/9cecc51a5250fa3ce69ff01aa3b93fe9 to your computer and use it in GitHub Desktop.
Save daformat/9cecc51a5250fa3ce69ff01aa3b93fe9 to your computer and use it in GitHub Desktop.
Create a html input slider to set the current html document root font-size
{
// Create a html input slider to set the current html document root font-size
// @returns the ref to the inserted DOM element
const createRootFontSizeSlider = (min = 8, max = 18) => {
const i = document.createElement("input")
i.type = "range"
i.min = `${min}`
i.max = `${max}`
i.step = "0.01"
i.style = "position: fixed; bottom: 24px; right: 24px; z-index: 2147483647"
i.value = `${parseFloat(getComputedStyle(document.documentElement).fontSize)}`
i.addEventListener("input", () => {
document.documentElement.style.setProperty("font-size", `${i.value}px`)
})
document.body.append(i)
return i
}
// call it with whatever min / max pixel size you want, or none to use defaults
const ref = createRootFontSizeSlider()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment