|
8 | 8 |
|
9 | 9 | </div>
|
10 | 10 |
|
11 |
| -[PostCSS] plugin to create smooth linear-gradients that approximate easing functions. |
| 11 | +<br> |
12 | 12 |
|
13 |
| -```css |
14 |
| -.demo { |
15 |
| - background: scrim-gradient( |
16 |
| - black, |
17 |
| - transparent |
18 |
| - ); |
| 13 | +[PostCSS](https://github.com/postcss/postcss) plugin to create smooth linear-gradients that approximate easing functions. |
19 | 14 |
|
20 |
| - background: ease-in-out-quad-gradient( |
21 |
| - to bottom left, |
22 |
| - #bada55, |
23 |
| - olive |
24 |
| - ); |
| 15 | +Visual examples and online editor on [larsenwork.com/easing-gradients](https://larsenwork.com/easing-gradients/) |
25 | 16 |
|
26 |
| - background: ease-in-sine-gradient( |
27 |
| - 23deg, |
28 |
| - hsla(300, 80%, 50%, 0.7), |
29 |
| - rgb(120, 140, 255) |
30 |
| - ); |
31 |
| -} |
32 |
| -``` |
| 17 | +⚠️ The [syntax](#syntax) has changed substantially in `^v.2.0.0` ⚠️ |
| 18 | + |
| 19 | +<br> |
33 | 20 |
|
34 |
| -becomes |
| 21 | +## Examples |
35 | 22 |
|
36 | 23 | ```css
|
37 |
| -.demo { |
| 24 | +.cubic-bezier { |
38 | 25 | background: linear-gradient(
|
| 26 | + to bottom, |
| 27 | + black, |
| 28 | + cubic-bezier(0.48, 0.30, 0.64, 1.00), |
| 29 | + transparent |
| 30 | + ); |
| 31 | + /* => */ |
| 32 | + background: linear-gradient( |
| 33 | + to bottom, |
39 | 34 | hsl(0, 0%, 0%) 0%,
|
40 |
| - hsla(0, 0%, 0%, 0.738) 19%, |
41 |
| - hsla(0, 0%, 0%, 0.541) 34%, |
42 |
| - hsla(0, 0%, 0%, 0.382) 47%, |
43 |
| - hsla(0, 0%, 0%, 0.278) 56.5%, |
44 |
| - hsla(0, 0%, 0%, 0.194) 65%, |
45 |
| - hsla(0, 0%, 0%, 0.126) 73%, |
46 |
| - hsla(0, 0%, 0%, 0.075) 80.2%, |
47 |
| - hsla(0, 0%, 0%, 0.042) 86.1%, |
48 |
| - hsla(0, 0%, 0%, 0.021) 91%, |
49 |
| - hsla(0, 0%, 0%, 0.008) 95.2%, |
50 |
| - hsla(0, 0%, 0%, 0.002) 98.2%, |
| 35 | + hsla(0, 0%, 0%, 0.94505) 7.9%, |
| 36 | + hsla(0, 0%, 0%, 0.88294) 15.3%, |
| 37 | + hsla(0, 0%, 0%, 0.81522) 22.2%, |
| 38 | + hsla(0, 0%, 0%, 0.7426) 28.7%, |
| 39 | + hsla(0, 0%, 0%, 0.66692) 34.8%, |
| 40 | + hsla(0, 0%, 0%, 0.58891) 40.6%, |
| 41 | + hsla(0, 0%, 0%, 0.50925) 46.2%, |
| 42 | + hsla(0, 0%, 0%, 0.42866) 51.7%, |
| 43 | + hsla(0, 0%, 0%, 0.34817) 57.2%, |
| 44 | + hsla(0, 0%, 0%, 0.2693) 62.8%, |
| 45 | + hsla(0, 0%, 0%, 0.19309) 68.7%, |
| 46 | + hsla(0, 0%, 0%, 0.12126) 75.2%, |
| 47 | + hsla(0, 0%, 0%, 0.05882) 82.6%, |
| 48 | + hsla(0, 0%, 0%, 0.01457) 91.2%, |
51 | 49 | hsla(0, 0%, 0%, 0) 100%
|
52 | 50 | );
|
| 51 | +} |
53 | 52 |
|
| 53 | +.ease { |
54 | 54 | background: linear-gradient(
|
55 |
| - to bottom left, |
56 |
| - hsl(74.4, 64.3%, 59.4%) 0%, |
57 |
| - hsl(74.2, 63.2%, 58.8%) 9.7%, |
58 |
| - hsl(73.5, 60.7%, 57.1%) 18.3%, |
59 |
| - hsl(72.6, 57.5%, 54.9%) 25.7%, |
60 |
| - hsl(71.5, 54.2%, 52.3%) 32.2%, |
61 |
| - hsl(70.4, 52.1%, 49.6%) 37.9%, |
62 |
| - hsl(69.2, 55.1%, 46.7%) 43.1%, |
63 |
| - hsl(67.9, 58.7%, 43.7%) 47.9%, |
64 |
| - hsl(66.7, 62.8%, 40.6%) 52.4%, |
65 |
| - hsl(65.4, 67.6%, 37.7%) 57.2%, |
66 |
| - hsl(64.2, 72.9%, 34.8%) 62.4%, |
67 |
| - hsl(63, 79%, 32%) 68.2%, |
68 |
| - hsl(61.9, 85.5%, 29.5%) 74.7%, |
69 |
| - hsl(60.9, 92.3%, 27.3%) 82.2%, |
70 |
| - hsl(60.2, 97.8%, 25.7%) 90.9%, |
71 |
| - hsl(60, 100%, 25.1%) 100% |
| 55 | + green, |
| 56 | + ease, |
| 57 | + red |
72 | 58 | );
|
73 |
| - |
74 |
| - |
| 59 | + /* => */ |
75 | 60 | background: linear-gradient(
|
76 |
| - 23deg, |
77 |
| - hsla(300, 80%, 50%, 0.7) 0%, |
78 |
| - hsla(299.1, 80.2%, 50.6%, 0.703) 9.7%, |
79 |
| - hsla(296.8, 80.7%, 52.1%, 0.713) 18.9%, |
80 |
| - hsla(293.3, 81.6%, 54.3%, 0.727) 27.4%, |
81 |
| - hsla(289.1, 82.6%, 56.7%, 0.745) 35.2%, |
82 |
| - hsla(284.3, 83.7%, 59.2%, 0.764) 42.5%, |
83 |
| - hsla(279.2, 85%, 61.7%, 0.786) 49.3%, |
84 |
| - hsla(274, 86.4%, 64%, 0.808) 55.7%, |
85 |
| - hsla(268.5, 87.8%, 66.2%, 0.831) 61.8%, |
86 |
| - hsla(263, 89.4%, 68.2%, 0.854) 67.7%, |
87 |
| - hsla(257.4, 91%, 70.1%, 0.878) 73.4%, |
88 |
| - hsla(251.8, 92.7%, 71.8%, 0.902) 78.9%, |
89 |
| - hsla(246.2, 94.4%, 73.4%, 0.927) 84.3%, |
90 |
| - hsla(240.6, 96.2%, 74.9%, 0.951) 89.6%, |
91 |
| - hsla(235.4, 98.3%, 74.3%, 0.976) 94.9%, |
92 |
| - hsl(231.1, 100%, 73.5%) 100% |
| 61 | + hsl(120, 100%, 25.1%) 0%, |
| 62 | + hsl(111.85, 100%, 23.5%) 7.8%, |
| 63 | + hsl(98.92, 100%, 21.34%) 13.2%, |
| 64 | + hsl(82.02, 100%, 19.05%) 17.6%, |
| 65 | + hsl(60.02, 100%, 16.71%) 21.7%, |
| 66 | + hsl(40.57, 100%, 21.3%) 25.8%, |
| 67 | + hsl(28.11, 100%, 25.86%) 30.2%, |
| 68 | + hsl(19.54, 100%, 30.32%) 35.1%, |
| 69 | + hsl(13.47, 100%, 34.55%) 40.6%, |
| 70 | + hsl(9.01, 100%, 38.49%) 46.9%, |
| 71 | + hsl(5.73, 100%, 42.01%) 54.1%, |
| 72 | + hsl(3.36, 100%, 44.98%) 62.2%, |
| 73 | + hsl(1.74, 100%, 47.28%) 71.1%, |
| 74 | + hsl(0.7, 100%, 48.86%) 80.6%, |
| 75 | + hsl(0.15, 100%, 49.74%) 90.5%, |
| 76 | + hsl(0, 100%, 50%) 100% |
93 | 77 | );
|
94 | 78 | }
|
95 |
| -``` |
96 | 79 |
|
97 |
| -## Usage |
98 |
| - |
99 |
| -```js |
100 |
| -postcss([ require('postcss-easing-gradients') ]) |
| 80 | +.steps { |
| 81 | + background: linear-gradient( |
| 82 | + to right, |
| 83 | + green, |
| 84 | + steps(4, skip-none), |
| 85 | + red |
| 86 | + ); |
| 87 | + /* => */ |
| 88 | + background: linear-gradient( |
| 89 | + to right, |
| 90 | + hsl(120, 100%, 25.1%) 0%, |
| 91 | + hsl(120, 100%, 25.1%) 25%, |
| 92 | + hsl(60.23, 100%, 16.73%) 25%, |
| 93 | + hsl(60.23, 100%, 16.73%) 50%, |
| 94 | + hsl(15.06, 100%, 33.33%) 50%, |
| 95 | + hsl(15.06, 100%, 33.33%) 75%, |
| 96 | + hsl(0, 100%, 50%) 75%, |
| 97 | + hsl(0, 100%, 50%) 100% |
| 98 | + ); |
| 99 | +} |
101 | 100 | ```
|
102 | 101 |
|
103 |
| -See [PostCSS] docs for examples for your environment. |
| 102 | +<br> |
104 | 103 |
|
105 | 104 | ## Syntax
|
106 | 105 |
|
107 |
| -The syntax is `<gradient-type>([ <direction>,]? <start-color>, <stop-color>)` where |
| 106 | +Ccurrently only a subset of the [full syntax](https://github.com/w3c/csswg-drafts/issues/1332#issuecomment-299990698) is supported: |
108 | 107 |
|
109 |
| -* `gradient-type` is one of the supported gradient types |
110 |
| -* `direction` shares syntax with `linear-gradient` and is optional |
111 |
| -* `start-color` and `stop-color` are css colors in any format |
| 108 | +```xml |
| 109 | +linear-gradient( |
| 110 | + [ <direction>,]? |
| 111 | + <color>, |
| 112 | + <animation-timing-function>, |
| 113 | + <color> |
| 114 | +) |
| 115 | +``` |
112 | 116 |
|
113 |
| -Note that it's exactly two colors and it doesn't support custom color stop locations. |
| 117 | +The steps syntax is also being figured out and currently [this](https://github.com/w3c/csswg-drafts/issues/1680#issuecomment-361550637) is supported. |
114 | 118 |
|
115 |
| -## Supported Gradient Types |
| 119 | +<br> |
116 | 120 |
|
117 |
| -```css |
118 |
| -ease-in-sine-gradient |
119 |
| -ease-out-sine-gradient |
120 |
| -ease-in-out-sine-gradient |
121 |
| -ease-in-quad-gradient |
122 |
| -ease-out-quad-gradient |
123 |
| -ease-in-out-quad-gradient |
124 |
| -scrim-gradient |
| 121 | +## Usage |
| 122 | + |
| 123 | +```js |
| 124 | +postcss([ require('postcss-easing-gradients') ]) |
125 | 125 | ```
|
126 | 126 |
|
| 127 | +See [PostCSS Usage](https://github.com/postcss/postcss#usage) docs for examples for your environment. |
| 128 | + |
| 129 | +<br> |
| 130 | + |
127 | 131 | ## Options
|
128 | 132 |
|
129 |
| -* `precision: 0.1` is the default value and creates ~17 color stops. I wouldn't recommending using anything above 0.2 as banding becomes very obvious. |
130 |
| -* `alphaDecimals: 3` is the default number of decimals for alpha values and I wouldn't recommend changing it. Increase it for greater precision. |
| 133 | +I wouldn't recommend tweaking from default values but: |
131 | 134 |
|
132 |
| -## Preview |
| 135 | +* `precision: 0.1` is the default and creates ~17 color stops. A higher number creates a more "low poly" gradient and banding becomes very visible when using anything above 0.2. |
| 136 | +* `alphaDecimals: 5` is the default. A lower number can result in banding. |
133 | 137 |
|
134 |
| - |
| 138 | +<br> |
135 | 139 |
|
136 | 140 | ## Demo
|
137 | 141 |
|
138 | 142 | Make sure that you have gulp cli installed and then `cd demo`, `npm install` and `gulp`.
|
139 | 143 |
|
140 | 144 | If you want to develop then `npm link` in project root and then `npm link postcss-easing-gradients`
|
141 | 145 |
|
| 146 | +<br> |
| 147 | + |
142 | 148 | ## Contributions
|
143 | 149 |
|
144 | 150 | Are more than welcome. Code is linted using:
|
145 | 151 |
|
146 | 152 | [![js-standard-style][js-img]][js]
|
147 | 153 |
|
148 |
| -[PostCSS]: https://github.com/postcss/postcss |
149 | 154 | [ci-img]: https://img.shields.io/travis/larsenwork/postcss-easing-gradients.svg
|
150 | 155 | [ci]: https://travis-ci.org/larsenwork/postcss-easing-gradients
|
151 | 156 | [js-img]: https://cdn.rawgit.com/feross/standard/master/badge.svg
|
|
0 commit comments