Created
July 28, 2014 05:10
-
-
Save DomenicoColandrea86/6a72779efadb7a02f710 to your computer and use it in GitHub Desktop.
automatically create image sprites with retina support using compass and scss!
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
@import "compass/utilities/sprites"; // Include compass sprite helpers | |
@import "compass/css3/background-size"; // Include helper to calc background size | |
// General Sprite Defaults | |
// You can override them before you import this file. | |
$icon-sprite-base-class: ".icon-sprite" !default; | |
$icon-sprite-dimensions: true !default; | |
$icon-spacing: 20px !default; | |
$icon-position: 0% !default; | |
$icon-repeat: no-repeat !default; | |
$icon-sprites: sprite-map("../../assets/img/sprite-img/icons/*.png", $spacing: $icon-spacing, $repeat: $icon-repeat, $position: $icon-position, $layout: horizontal); | |
$icon-sprites-retina: sprite-map("../../assets/img/sprite-img/icons-retina/*.png", $spacing: $icon-spacing * 2, $repeat: $icon-repeat, $position: $icon-position, $layout: horizontal); | |
// All sprites should extend this class | |
// The icon-sprite mixin will do so for you. | |
#{$icon-sprite-base-class} { | |
@include inline-block; | |
background: $icon-sprites $icon-repeat; | |
} | |
@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), (min-resolution: 1.5dppx) { | |
#{$icon-sprite-base-class} { | |
background: $icon-sprites-retina $icon-repeat; | |
@include background-size(round(image-width(sprite-path($icon-sprites-retina)) / 2) auto); | |
} | |
} | |
// Extends the sprite base class and set the background position for the desired sprite. | |
// It will also apply the image dimensions if $dimensions is true. | |
@mixin icon-sprite($name, $dimensions: $icon-sprite-dimensions, $offset-x: 0, $offset-y: 0) { | |
@extend #{$icon-sprite-base-class}; | |
@include sprite($icon-sprites, $name, $dimensions, $offset-x, $offset-y) | |
} | |
// EXAMPLE USAGE: | |
// ------------- | |
// .some-class { | |
// @inlcude icon-sprite(NAME_OF_IMAGE); | |
// } | |
// ------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment