Skip to content

Instantly share code, notes, and snippets.

@annez
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save annez/cfc227928eba4e51f0f3 to your computer and use it in GitHub Desktop.
Save annez/cfc227928eba4e51f0f3 to your computer and use it in GitHub Desktop.
HIDPI compass image mixin
/// Returns a normal or 2x image depending on the DPI of the screen.
///
/// @author David Annez
///
/// @param {String} $image-path
/// The path to the image
///
/// @param {String} $format [".png"]
/// The format of the file
@mixin hidpi-image($image-path, $format: ".png") {
$width: #{image-width(#{$image-path}#{$format})};
$height: #{image-height(#{$image-path}#{$format})};
background-size: unquote("#{$width} #{$height}");
background-image: image-url("#{$image-path}#{$format}");
@media screen and (-webkit-min-device-pixel-ratio: 1.5), screen and (min--moz-device-pixel-ratio: 1.5), screen and (-o-device-pixel-ratio: 3 / 2), screen and (min-device-pixel-ratio: 1.5) {
background-image: image-url("#{$image-path}-2x#{$format}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment