| 1 |
// @doc off |
| 2 |
// Example 1: |
| 3 |
// |
| 4 |
// a.twitter |
| 5 |
// +sprite-img("icons-32.png", 1) |
| 6 |
// a.facebook |
| 7 |
// +sprite-img("icons-32png", 2) |
| 8 |
// |
| 9 |
// Example 2: |
| 10 |
// |
| 11 |
// a |
| 12 |
// +sprite-background("icons-32.png") |
| 13 |
// a.twitter |
| 14 |
// +sprite-column(1) |
| 15 |
// a.facebook |
| 16 |
// +sprite-row(2) |
| 17 |
// @doc on |
| 18 |
|
| 19 |
$sprite-default-size: 32px !default; |
| 20 |
|
| 21 |
$sprite-default-margin: 0px !default; |
| 22 |
|
| 23 |
$sprite-image-default-width: $sprite-default-size !default; |
| 24 |
|
| 25 |
$sprite-image-default-height: $sprite-default-size !default; |
| 26 |
|
| 27 |
// Sets all the rules for a sprite from a given sprite image to show just one of the sprites. |
| 28 |
// To reduce duplication use a sprite-bg mixin for common properties and a sprite-select mixin for positioning. |
| 29 |
@mixin sprite-img($img, $col, $row: 1, $width: $sprite-image-default-width, $height: $sprite-image-default-height, $margin: $sprite-default-margin) { |
| 30 |
@include sprite-background($img, $width, $height); |
| 31 |
@include sprite-position($col, $row, $width, $height, $margin); |
| 32 |
} |
| 33 |
|
| 34 |
// Sets rules common for all sprites, assumes you want a square, but allows a rectangular region. |
| 35 |
@mixin sprite-background($img, $width: $sprite-default-size, $height: $width) { |
| 36 |
@include sprite-background-rectangle($img, $width, $height); |
| 37 |
} |
| 38 |
|
| 39 |
// Sets rules common for all sprites, assumes a rectangular region. |
| 40 |
@mixin sprite-background-rectangle($img, $width: $sprite-image-default-width, $height: $sprite-image-default-height) { |
| 41 |
background: image-url($img) no-repeat; |
| 42 |
width: $width; |
| 43 |
height: $height; |
| 44 |
overflow: hidden; |
| 45 |
} |
| 46 |
|
| 47 |
// Allows horizontal sprite positioning optimized for a single row of sprites. |
| 48 |
@mixin sprite-column($col, $width: $sprite-image-default-width, $margin: $sprite-default-margin) { |
| 49 |
@include sprite-position($col, 1, $width, 0px, $margin); |
| 50 |
} |
| 51 |
|
| 52 |
// Allows vertical sprite positioning optimized for a single column of sprites. |
| 53 |
@mixin sprite-row($row, $height: $sprite-image-default-height, $margin: $sprite-default-margin) { |
| 54 |
@include sprite-position(1, $row, 0px, $height, $margin); |
| 55 |
} |
| 56 |
|
| 57 |
// Allows vertical and horizontal sprite positioning from a grid of equal dimensioned sprites. |
| 58 |
@mixin sprite-position($col, $row: 1, $width: $sprite-image-default-width, $height: $sprite-image-default-height, $margin: $sprite-default-margin) { |
| 59 |
$x: ($col - 1) * -$width - ($col - 1) * $margin; |
| 60 |
$y: ($row - 1) * -$height - ($row - 1) * $margin; |
| 61 |
background-position: $x $y; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
// Similar to 'sprite-replace-text-with-dimensions' but does not autmaticly set the demensions |
| 67 |
@mixin sprite-replace-text ($map, $sprite, $dimensions: false, $offset-x: 0, $offset-y: 0) { |
| 68 |
@include hide-text; |
| 69 |
@include sprite($map, $sprite, $dimensions, $offset-x, $offset-y); |
| 70 |
background-image: $map; |
| 71 |
background-repeat: no-repeat; |
| 72 |
} |
| 73 |
|
| 74 |
// Similar to 'replace-text-with-dimensions' but with sprites |
| 75 |
// To use, create your sprite and then pass it in the `$map` param |
| 76 |
// The name of the image in the sprite folder should be `$img-name` |
| 77 |
@mixin sprite-replace-text-with-dimensions ($map, $sprite, $offset-x: 0, $offset-y: 0){ |
| 78 |
@include sprite-replace-text ($map, $sprite, true, $offset-x, $offset-y); |
| 79 |
} |