Skip to content

Instantly share code, notes, and snippets.

@1-800-jono
Last active February 6, 2018 20:45
Show Gist options
  • Save 1-800-jono/728eadf09fa6f5e6c76853e190f2c7b9 to your computer and use it in GitHub Desktop.
Save 1-800-jono/728eadf09fa6f5e6c76853e190f2c7b9 to your computer and use it in GitHub Desktop.
Creates fluid/responsive properties using JS
//The fp() “Fluid Property” SCSS mixin
export function fp(property, min, max, start = 320, end = 1400, clip = true, clipAtStart = true, clipAtEnd = true) {
const multiplier = (max - min) / (end - start) * 100;
const adder = (min * end - max * start) / (end - start);
const formula = `calc((${multiplier}vw) + (${adder}px))`;
return`
@media (max-width: ${start}px) {
${property}: ${min}px;
}
@media (min-width: ${end}px) {
${property}: ${max}px;
}
${property}: ${formula};
`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment