Skip to content

Instantly share code, notes, and snippets.

@tevko
Last active January 31, 2016 10:31
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save tevko/f46accc3ce788a3594a0 to your computer and use it in GitHub Desktop.
Save tevko/f46accc3ce788a3594a0 to your computer and use it in GitHub Desktop.
Dev Tools Snippet to auto-calculate responsive image sizes value on window resize
/**
*
* Paste image class / identifier in IIFE parenthesis at end of function
*
* */
(function(i){"use strict";var img=$(i),sizes=[];window.addEventListener("resize",()=>{var vw=Math.round(((img.offsetWidth*100)/window.innerWidth))+"vw",mq="(min-width: "+window.innerWidth+"px)",value=vw;vw!=="0vw"&&sizes.indexOf(vw)===-1&&(sizes.push(value),console.log(mq,vw))})})("PASTE CLASS OR IDENTIFIER HERE");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment