Created
February 7, 2022 18:15
-
-
Save hjJunior/8bd2ff6ae0ba5b69df4990f7f3b50bf8 to your computer and use it in GitHub Desktop.
Adjust the root text to be automatically responsible
This file contains hidden or 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
function clampBuilder( minWidthPx, maxWidthPx, minFontSize, maxFontSize ) { | |
const root = document.querySelector( "html" ); | |
const pixelsPerRem = Number( getComputedStyle( root ).fontSize.slice( 0,-2 ) ); | |
const minWidth = minWidthPx / pixelsPerRem; | |
const maxWidth = maxWidthPx / pixelsPerRem; | |
const slope = ( maxFontSize - minFontSize ) / ( maxWidth - minWidth ); | |
const yAxisIntersection = -minWidth * slope + minFontSize | |
return `clamp( ${ minFontSize }rem, ${ yAxisIntersection }rem + ${ slope * 100 }vw, ${ maxFontSize }rem )`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment