Created
July 13, 2012 15:05
-
-
Save dfadler/3105369 to your computer and use it in GitHub Desktop.
A SASS mixin for generating a sprite declaration block that will work with media queries
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
// http://compass-style.org/reference/compass/helpers/sprites/ | |
@mixin get-sprite($map, $sprite, $repeat: no-repeat, $height: true, $width: true) | |
//http://compass-style.org/reference/compass/helpers/sprites/#sprite-file | |
$sprite-image: sprite-file($map, $sprite) | |
// http://compass-style.org/reference/compass/helpers/sprites/#sprite-url | |
$sprite-map: sprite-url($map) | |
// http://compass-style.org/reference/compass/helpers/sprites/#sprite-position | |
$sprite-position: sprite-position($map, $sprite) | |
// Returns background | |
background: $sprite-map $sprite-position $repeat | |
// http://compass-style.org/reference/compass/helpers/image-dimensions/ | |
// Checks to see if the user wants height returned | |
@if $height == true | |
// Gets the height of the sprite-image | |
$sprite-height: image-height($sprite-image) | |
// Returns the height | |
height: $sprite-height | |
// http://compass-style.org/reference/compass/helpers/image-dimensions/ | |
// Checks to see if the user wants height returned | |
@if $width == true | |
// Gets the height of the sprite-image | |
$sprite-width: image-width($sprite-image) | |
// Returns the width | |
width: $sprite-width |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for that mixin.
I just wondered how to use get-sprite in conjunction with a magic import.
My first try was to do it by my own with 'sprite-map("my-icons/.png");', but that fails as the two sprite maps are conflicting- see the first comment.
Simple & straight solution: It`s not so obvious but compass will create a variable during a magic import which holds the reference to the generated sprite map. This reference can be used with the mixin as the first argument.
Example: @import "my-icons/.png" will provide the variable $my-icons-sprites.
Anyway thanks for the mixin, finally I can change my sprite icons inside my media queries :)