1 | //************************************************************************// |
---|
2 | // Background-image property for adding multiple background images with |
---|
3 | // gradients, or for stringing multiple gradients together. |
---|
4 | //************************************************************************// |
---|
5 | |
---|
6 | @mixin background-image($images...) { |
---|
7 | background-image: _add-prefix($images, webkit); |
---|
8 | background-image: _add-prefix($images); |
---|
9 | } |
---|
10 | |
---|
11 | @function _add-prefix($images, $vendor: false) { |
---|
12 | $images-prefixed: (); |
---|
13 | $gradient-positions: false; |
---|
14 | @for $i from 1 through length($images) { |
---|
15 | $type: type-of(nth($images, $i)); // Get type of variable - List or String |
---|
16 | |
---|
17 | // If variable is a list - Gradient |
---|
18 | @if $type == list { |
---|
19 | $gradient-type: nth(nth($images, $i), 1); // linear or radial |
---|
20 | $gradient-pos: null; |
---|
21 | $gradient-args: null; |
---|
22 | |
---|
23 | @if ($gradient-type == linear) or ($gradient-type == radial) { |
---|
24 | $gradient-pos: nth(nth($images, $i), 2); // Get gradient position |
---|
25 | $gradient-args: nth(nth($images, $i), 3); // Get actual gradient (red, blue) |
---|
26 | } |
---|
27 | @else { |
---|
28 | $gradient-args: nth(nth($images, $i), 2); // Get actual gradient (red, blue) |
---|
29 | } |
---|
30 | |
---|
31 | $gradient-positions: _gradient-positions-parser($gradient-type, $gradient-pos); |
---|
32 | $gradient: _render-gradients($gradient-positions, $gradient-args, $gradient-type, $vendor); |
---|
33 | $images-prefixed: append($images-prefixed, $gradient, comma); |
---|
34 | } |
---|
35 | // If variable is a string - Image |
---|
36 | @else if $type == string { |
---|
37 | $images-prefixed: join($images-prefixed, nth($images, $i), comma); |
---|
38 | } |
---|
39 | } |
---|
40 | @return $images-prefixed; |
---|
41 | } |
---|
42 | |
---|
43 | //Examples: |
---|
44 | //@include background-image(linear-gradient(top, orange, red)); |
---|
45 | //@include background-image(radial-gradient(50% 50%, cover circle, orange, red)); |
---|
46 | //@include background-image(url("/images/a.png"), linear-gradient(orange, red)); |
---|
47 | //@include background-image(url("image.png"), linear-gradient(orange, red), url("image.png")); |
---|
48 | //@include background-image(linear-gradient(hsla(0, 100%, 100%, 0.25) 0%, hsla(0, 100%, 100%, 0.08) 50%, transparent 50%), linear-gradient(orange, red)); |
---|