Skip to content

Instantly share code, notes, and snippets.

@cacheflowe
Last active October 5, 2015 22:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cacheflowe/2885138 to your computer and use it in GitHub Desktop.
Save cacheflowe/2885138 to your computer and use it in GitHub Desktop.
Media queries to load only 1 image per browser width / pixel density
// webkit-only .sass --------------------------------
@media (min-width: 20px) and (max-width: 480px) and (-webkit-min-device-pixel-ratio: 1.5)
#site-loader-inner
background: transparent url('mobile/loaders/loader-spin@2x.png', image)
@media (min-width: 20px) and (max-width: 480px) and (-webkit-max-device-pixel-ratio: 1.5)
#site-loader-inner
background: transparent url('mobile/loaders/loader-spin.png', image)
// retina-respond.scss mixin -------------------------------
@mixin respond-to($media) {
@if $media == nonretina {
@media (-webkit-max-device-pixel-ratio: 1.5), (max-resolution: 143dpi) { @content; }
}
@else if $media == retina {
@media (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi) { @content; }
}
}
// example use:
@include respond-to(nonretina)
background: $white-bg url($file-fire) center top no-repeat
@include respond-to(retina)
background: $white-bg url($file-fire-2x) center top no-repeat
background-size: 311px 208px
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment