Skip to content

Instantly share code, notes, and snippets.

@robtarr
Created August 20, 2012 18:13
Show Gist options
  • Save robtarr/3406292 to your computer and use it in GitHub Desktop.
Save robtarr/3406292 to your computer and use it in GitHub Desktop.
Retina/HD SASS mix-in
This is totally just a thought. Untested and unfinished.
Trying to make sure images aren't needlessly being downloaded.
@mixin hd($path, $img) {
@media (-webkit-max-device-pixel-ratio: 1.49),
(-o-max-device-pixel-ratio: 3/2.01),
(max-device-pixel-ratio: 1.49) {
background-image: url($path + "/" + $img);
}
@media (-webkit-min-device-pixel-ratio: 1.5),
(-o-min-device-pixel-ratio: 3/2),
(min-device-pixel-ratio: 1.5) {
background-image: url($path + "/hd/" + $img);
background-size: image-width($path + "/" + $img) image-height($path + "/" + $img);
}
.no-mq & {
background-image: url($path + "/" + $img);
}
}
body {
@include hd( "../img", "background-image.jpg");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment