Last active
December 10, 2015 22:28
-
-
Save mitchellhillman/4501905 to your computer and use it in GitHub Desktop.
Retina Sprite mixin using SCSS and COMPASS
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
// COMPASS | |
@import "compass/utilities/sprites"; | |
@import "compass/css3/background-size"; | |
// Import Images | |
$sprites: sprite-map("sprites/*.png"); | |
$sprites2x: sprite-map("sprites-retina/*.png"); | |
@mixin sprite($name) { | |
@include retina-sprite($name, $sprites, $sprites2x); | |
} | |
@mixin retina-sprite($name, $sprites, $sprites2x, $dimensions: true) { | |
display: block; | |
background-image: sprite-url($sprites); | |
background-position: sprite-position($sprites, $name); | |
background-repeat: no-repeat; | |
@if $dimensions == true { | |
@include sprite-dimensions($sprites, $name); | |
} | |
@media (-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-device-pixel-ratio: 1.5) { | |
& { | |
$pos: sprite-position($sprites2x, $name); | |
background-image: sprite-url($sprites2x); | |
background-position: nth($pos, 1) nth($pos, 2)/2; | |
@include background-size(ceil(image-width(sprite-path($sprites2x)) / 2), auto); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment