Created
April 26, 2019 13:15
-
-
Save carlfairclough/01b32e3d54d4c323caf560503682c04d to your computer and use it in GitHub Desktop.
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
function cssGrad (p1, p2){ | |
// Based on y = mx + b | |
let m = ((p2.y - p1.y) / (p2.x - p1.x)).toFixed(5) | |
// Place space between "-" and number if negative | |
m < 0 && (m = '- ' + (m * -1)) | |
// p1.y = (m * p1.x) + b | |
let b = p1.y - (m * p1.x) | |
// Place space between "-" and number if negative | |
b < 0 ? b = '- ' + (b * -1).toFixed(2) : b = '+ ' + b.toFixed(2) | |
return 'calc( ' + (m * 100).toFixed(2) + 'vw ' + b + 'px )' | |
} | |
const example = { | |
fontSize: 36, | |
// SCALE TO 45 @ 768 | |
'@media(min-width: 375px)': { | |
fontSize: cssGrad({x:375, y: 36},{x:768, y: 45}) | |
}, | |
// SCALE TO 75 @ 1440 | |
'@media(min-width: 1024px)': { | |
fontSize: cssGrad({x:1024, y: 53},{x: 1440, y: 75} ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment