forked from drublic/Sass-Mixins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_multiple-colored-gradient.scss
84 lines (77 loc) · 2.07 KB
/
_multiple-colored-gradient.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
///
/// This mixin creates (endless) multiple color stops in gradients just with one
/// call for the mixin.
///
/// Note: This mixin does not define a fallback-color for your background as it
/// is likely you want to add an image or something. Please specify one by
/// yourself.
///
/// @author drublic
///
/// @link http://caniuse.com/css-gradients caniuse
/// @link http://www.w3.org/TR/2011/WD-css3-images-20110217/#linear-gradients spec
///
/// @param {Arglist} $args
///
/// @output
/// ```css
/// background-image: -webkit-linear-gradient(top, <stops[1]>, <stops[2]>, ..., <stops[n]>);
/// background-image: linear-gradient(to bottom, <stops[1]>, <stops[2]>, ..., <stops[n]>);
/// ```
///
/// @example
/// .selector {
/// @include x-multiple-colored-gradient(
/// 'top',
/// #f22 0%,
/// #f2f 15%,
/// #22f 30%,
/// #2ff 45%,
/// #2f2 60%,
/// #2f2 75%,
/// #ff2 90%,
/// #f22 100%
/// );
/// }
///
@mixin x-multiple-colored-gradient ($args...) {
$gradient: ();
$pos: nth($args, 1);
$pos_newsyntax: ();
@if not is-valid-keyword-direction($pos) {
$pos: 'top';
}
// New Syntax
@if $pos == 'top' {
$pos_newsyntax: 'to bottom';
} @else if $pos == 'right' {
$pos_newsyntax: 'to left';
} @else if $pos == 'bottom' {
$pos_newsyntax: 'to top';
} @else if $pos == 'left' {
$pos_newsyntax: 'to right';
}
@each $g in $args {
@if not is-valid-keyword-direction($g) {
$gradient: append($gradient, $g, comma);
}
}
background-image: -webkit-linear-gradient(unquote($pos), $gradient);
background-image: linear-gradient(unquote($pos_newsyntax), $gradient);
}
///
/// Returns whether a value is a valid keyword direction.
///
/// @param {String} $value
///
/// @returns {Bool}
///
@function is-valid-keyword-direction($value) {
@return not not index(
'top' 'right' 'bottom' 'left'
'to top' 'to right' 'to bottom' 'to left'
'to top right' 'to right top'
'to bottom right' 'to right bottom'
'to top left' 'to left top'
'to bottom left' 'to left bottom', $value);
}