-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy path_retina-sprites.scss
70 lines (63 loc) · 2.69 KB
/
_retina-sprites.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
@import "compass/utilities/sprites"; // Include compass sprite helpers
@import "compass/css3/background-size"; // Include helper to calc background size
@mixin retina-sprite($name, $hover: false, $active: false) {
@include _retina-sprite($name, $sprites, $sprites2x, $hover, $active);
}
// The general purpose retina sprite mixin.
//
// @include retina-sprite(name, $spritemap1, $spritemap2)
// @include retina-sprite(name, $spritemap1, $spritemap2[, $dimensions: true, $pad: 0])
//
// If `dimensions` is true, then width/height will also be set.
//
// if `pad` is non-zero, then that's how much padding the element will have (requires
// $spacing on the sprite maps). Great for iPhone interfaces to make hit areas bigger.
//
@mixin _retina-sprite($name, $sprites, $sprites2x, $hover, $active, $dimensions: true, $pad: 0) {
@if $dimensions == true {
@include sprite-dimensions($sprites, $name);
}
background-image: sprite-url($sprites);
background-position: sprite-position($sprites, $name, -$pad, -$pad);
background-repeat: no-repeat;
@if $hover == true {
$name_hover: $name + _hover;
&:hover {
background-position: sprite-position($sprites, $name_hover, -$pad, -$pad);
}
}
@if $active == true {
$name_active: $name + _active;
&:active {
background-position: sprite-position($sprites, $name_active, -$pad, -$pad);
}
}
@if $pad > 0 {
padding: $pad;
}
@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: 144dpi) {
& {
$pos: sprite-position($sprites2x, $name, -$pad * 2, -$pad * 2);
background-image: sprite-url($sprites2x);
background-position: nth($pos, 1) / 2 nth($pos, 2) / 2;
@include background-size(ceil(image-width(sprite-path($sprites2x)) / 2) auto);
// sprite-path() returns the path of the generated sprite sheet, which
// image-width() calculates the width of. the ceil() is in place in case
// you have sprites that have an odd-number of pixels in width
@if $hover == true {
$name_hover: $name + _hover; // create myButton_hover and assign it
&:hover{
$pos: sprite-position($sprites2x, $name_hover, -$pad * 2, -$pad * 2);
background-position: nth($pos, 1) / 2 nth($pos, 2) / 2;
}
}
@if $active == true {
$name_active: $name + _active; // create myButton_active and assign it
&:active{
$pos: sprite-position($sprites2x, $name_active, -$pad * 2, -$pad * 2);
background-position: nth($pos, 1) / 2 nth($pos, 2) / 2;
}
}
}
}
}