Last active
December 17, 2015 03:09
-
-
Save elentok/5541430 to your computer and use it in GitHub Desktop.
mixins for retina support
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 retina-image($image) { | |
| background-image: url(image-path("#{$image}.png")); | |
| @media (-webkit-min-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-device-pixel-ratio: 1.5) { | |
| background-image: url(image-path("#{$image}@2x.png")); | |
| } | |
| } | |
| @mixin retina-inline-image($image) { | |
| background-image: inline-image("#{$image}.png"); | |
| @media (-webkit-min-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-device-pixel-ratio: 1.5) { | |
| background-image: inline-image("#{$image}@2x.png"); | |
| } | |
| } | |
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
| $sprites: sprite-map("sprites/*.png"); | |
| $sprites-retina: sprite-map("sprites-retina/*.png"); | |
| @mixin sprite-background($name) { | |
| background-image: sprite-url($sprites); | |
| background-position: sprite-position($sprites, $name); | |
| background-repeat: no-repeat; | |
| display: inline-block; | |
| height: image-height(sprite-file($sprites, $name)); | |
| width: image-width(sprite-file($sprites, $name)); | |
| @media (-webkit-min-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-device-pixel-ratio: 1.5) { | |
| // Workaround for https://gist.github.com/2140082 | |
| @if (sprite-position($sprites, $name) != sprite-position($sprites-retina, $name)) { | |
| $ypos: round(nth(sprite-position($sprites-retina, $name), 2) / 2); | |
| background-position: 0 $ypos; | |
| } | |
| // Hard coded width of the normal sprite image. There must be a smarter way to do this. | |
| $file_width: image-width(sprite-path($sprites)); | |
| @include background-size($file_width auto); | |
| background-image: sprite-url($sprites-retina); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment