Last active
July 12, 2022 12:05
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// 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