sprite.less
2.79 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
LESS variables are information about icon's compiled state, stored under its original file name
.icon-home {
width: @icon-home-width;
}
The large array-like variables contain all information about a single icon
@icon-home: x y offset_x offset_y width height total_width total_height image_path name;
At the bottom of this section, we provide information about the spritesheet itself
@spritesheet: width height image @spritesheet-sprites;
*/
@btn-modal-name: 'btn-modal';
@btn-modal-x: 0px;
@btn-modal-y: 0px;
@btn-modal-offset-x: 0px;
@btn-modal-offset-y: 0px;
@btn-modal-width: 61px;
@btn-modal-height: 26px;
@btn-modal-total-width: 61px;
@btn-modal-total-height: 71px;
@btn-modal-image: '../img/sprite.png';
@btn-modal: 0px 0px 0px 0px 61px 26px 61px 71px '../img/sprite.png' 'btn-modal';
@logo-modal-name: 'logo-modal';
@logo-modal-x: 0px;
@logo-modal-y: 31px;
@logo-modal-offset-x: 0px;
@logo-modal-offset-y: -31px;
@logo-modal-width: 40px;
@logo-modal-height: 40px;
@logo-modal-total-width: 61px;
@logo-modal-total-height: 71px;
@logo-modal-image: '../img/sprite.png';
@logo-modal: 0px 31px 0px -31px 40px 40px 61px 71px '../img/sprite.png' 'logo-modal';
@spritesheet-width: 61px;
@spritesheet-height: 71px;
@spritesheet-image: '../img/sprite.png';
@spritesheet-sprites: @btn-modal @logo-modal;
@spritesheet: 61px 71px '../img/sprite.png' @spritesheet-sprites;
/*
The provided classes are intended to be used with the array-like variables
.icon-home {
.sprite-width(@icon-home);
}
.icon-email {
.sprite(@icon-email);
}
Example usage in HTML:
`display: block` sprite:
<div class="icon-home"></div>
To change `display` (e.g. `display: inline-block;`), we suggest using a common CSS class:
// CSS
.icon {
display: inline-block;
}
// HTML
<i class="icon icon-home"></i>
*/
.sprite-width(@sprite) {
width: extract(@sprite, 5);
}
.sprite-height(@sprite) {
height: extract(@sprite, 6);
}
.sprite-position(@sprite) {
@sprite-offset-x: extract(@sprite, 3);
@sprite-offset-y: extract(@sprite, 4);
background-position: @sprite-offset-x @sprite-offset-y;
}
.sprite-image(@sprite) {
@sprite-image: extract(@sprite, 9);
@sprite-image-bare: ~`"@{sprite-image}".slice(1, -1)`;
background-image: url(@sprite-image-bare);
}
.sprite(@sprite) {
.sprite-image(@sprite);
.sprite-position(@sprite);
.sprite-width(@sprite);
.sprite-height(@sprite);
}
/*
The `.sprites` mixin generates identical output to the CSS template
but can be overridden inside of LESS
This must be run when you have at least 2 sprites.
If run with a single sprite, then there will be reference errors.
.sprites(@spritesheet-sprites);
*/
.sprites(@sprites, @i: 1) when (@i <= length(@sprites)) {
@sprite: extract(@sprites, @i);
@sprite-name: e(extract(@sprite, 10));
.@{sprite-name} {
.sprite(@sprite);
}
.sprites(@sprites, @i + 1);
}