Last active
October 26, 2019 22:18
-
-
Save zlwaterfield/20a8d510d01f7e9f36c54af3a48379de to your computer and use it in GitHub Desktop.
Blog code snippet - https://medium.com/gofaros/dynamic-and-responsive-svg-3de87f757e0d
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
scale() { | |
// At 350px screen width the pathHeight coefficient should be 1 | |
const startPathHeight = 1; | |
const startScreenWidth = 350; | |
// At 450px screen width the pathHeight coefficient should be .69 | |
const midPathHeight = .69; | |
const midScreenWidth = 450; | |
// At 600px screen width the pathHeight coefficient should be .48 | |
const endPathHeight = .48; | |
const endScreenWidth = 600; | |
const lgWidth = 1204; | |
const onResize = () => { | |
let pathHeight; | |
if (window.innerWidth < midScreenWidth) { | |
pathHeight = startPathHeight + (((startPathHeight - midPathHeight) / (Math.pow(midScreenWidth, .1) - Math.pow(startScreenWidth, .1))) * (Math.pow(startScreenWidth, .1) - Math.pow(window.innerWidth, .1))); | |
} else if (window.innerWidth < endScreenWidth) { | |
pathHeight = midPathHeight + (((midPathHeight - endPathHeight) / (Math.pow(endScreenWidth, .1) - Math.pow(midScreenWidth, .1))) * (Math.pow(midScreenWidth, .1) - Math.pow(window.innerWidth, .1))); | |
} else if (window.innerWidth > lgWidth) { | |
pathHeight = 8; | |
} else { | |
pathHeight = 78 - 2 * Math.sqrt(window.innerWidth); | |
} | |
this.pathHeight = +pathHeight.toFixed(4); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment