Last active
December 26, 2015 07:29
-
-
Save KATT/7115347 to your computer and use it in GitHub Desktop.
SCSS mixin for retina background images
This file contains hidden or 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
@mixin background-image2x($image, $extension: 'png') { | |
$imageOrig: "#{$image}.#{$extension}"; | |
$image2x: "#{$image}@2x.#{$extension}"; | |
$width: image-width($imageOrig); | |
$height: image-height($imageOrig); | |
background-image: image-url($imageOrig); | |
@media (min--moz-device-pixel-ratio: 1.3), | |
(-o-min-device-pixel-ratio: 2.6/2), | |
(-webkit-min-device-pixel-ratio: 1.3), | |
(min-device-pixel-ratio: 1.3), | |
(min-resolution: 1.3dppx) { | |
/* on retina, use image that's scaled by 2 */ | |
background-image: image-url($image2x); | |
background-size: $width $height; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment