You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You will need React ++16.8 to make this library work, since it use hooks as it's main construction.
@@ -127,11 +140,7 @@ This hook returns an RGB color that changes with the scroll, using an startColor
127
140
128
141
This hook takes an object with 3 properties, "startColor" and "endColor" that are arrays of number with a length of 3. Each value in the array is a color representing RGB, so each value should be between 0 and 255. That means that each array should be like: [123, 2, 215] or [0, 0, 0] or [255, 255, 255 ]. The third property is "elementRef" that is an HTML Reference that you can get using the useRef hook.
129
142
130
-
Also it accepts an options object, to modify the behavior of the hook, options for now has just one property: anchor
131
-
132
-
anchor property is a string that can only be: "top", "middle" and "bottom". Its default value is "middle".
133
-
134
-
This represents which edge of the component will use the hook to calculate the current color. My recomendations are that you test it by yourself to see how it works. But I can tell you that if you have a component that is at the very top of your page, use anchor: "top" and if you have a component at the very bottom of your page, something like a footer, use anchor: "bottom".
143
+
Also it accepts an options object. Refer to [Linear Values Options](#linear-values-options) for more information.
135
144
136
145
It returns and string as: ```"rgb(123, 0, 43)"```
137
146
@@ -154,11 +163,6 @@ const DynamicBackground = ({
154
163
startColor: [123, 0, 24], //The color will vary from here
155
164
endColor: [45, 34, 12], // To here
156
165
elementRef: elementRef, //Using the height and the position of this element
157
-
158
-
// Neither options or anchor are needed in this case because it will always have middle as default value, I just use it for example purposes
159
-
options: {
160
-
anchor:"middle"// Because this will cover all the app, since is a background
@@ -185,11 +189,7 @@ This hook returns a value that changes on scroll, using an startValue and an end
185
189
186
190
This hook takes an object with 3 properties, "startValue" and "endValue" that are numbers. The third property is "elementRef" that is an HTML Reference that you can get using the useRef hook.
187
191
188
-
Also it accepts an options object, to modify the behavior of the hook, options for now has just one property: anchor
189
-
190
-
anchor property is a string that can only be: "top", "middle" and "bottom". Its default value is "middle".
191
-
192
-
This represents which edge of the component will use the hook to calculate the current color. My recomendations are that you test it by yourself to see how it works. But I can tell you that if you have a component that is at the very top of your page, use anchor: "top" and if you have a component at the very bottom of your page, something like a footer, use anchor: "bottom".
192
+
Also it accepts an options object. Refer to [Linear Values Options](#linear-values-options) for more information.
193
193
194
194
It returns the current value as number.
195
195
@@ -289,7 +289,52 @@ function Example() {
289
289
290
290
This lib provides an enumfor TypeScript users, it just has four properties at the moment:Directions.up, Directions.down, Directions.right and Directions.left that returns the value of"UP", "DOWN""RIGHT" and "LEFT", you can use it as helper for useDirection hook.
291
291
292
-
# Animations Components
292
+
293
+
## Linear Values Options
294
+
295
+
This options let you modify the behavior of the animations, is an object that useDynamicColor and useLinearValues use in their "options" property, it has 3 properties:"anchor", "delay" and "duration".
296
+
297
+
### Anchor property
298
+
299
+
It accepts 3 possible values as strings:"top", "middle" and "bottom". This refers to the edge of where the hook should make the calculations.
300
+
301
+
For example:
302
+
303
+
- top: Refers to the top edge of your component, the animation will last until the bottom of your component touches the top of the viewport, so this anchor is perfect for header components that are at the very top of your app. This anchor takes the component height as reference.
304
+
305
+
- middle: Refers to the exact middle of your component, the animation will last until the center of the component is out of the viewport, so this anchor is perfect for components that are floating near the center of some parent component. This anchor takes the viewport height as reference if the component height is less than viewport height.
306
+
307
+
- bottom: Refers to the bottom edge of your component, the animation will last until the bottom of your component aligns to the bottom of the viewport, so this anchor is perfect for footer compoennts that are at the very bottom of your app. This anchor takes the component height as reference.
308
+
309
+
### Delay property
310
+
311
+
It accepts a number, that should be between 0 and 100, it refers to percentage. If you pass values that are out of range it will be clamped to 0 or 100.
312
+
313
+
This means that, if you pass 50 the animation will delay to the 50%of the height of the component or viewport (depends on the anchor you use and the height of your component).
314
+
315
+
So, let's say we are using a component of 1000px height as reference and we set delay as 30% and anchor as "middle".
316
+
317
+
The animation won't start until the center of the screen (middle anchor) is at 300px (30%of1000px) of the center of the component.
318
+
319
+
320
+
### Duration property
321
+
322
+
It accepts a number, that should be between 0 and 100, it refers to percentage. If you pass values that are out of range it will be clamped to 0 or 100.
323
+
324
+
This means that, if you pass 50 the animation will last long to the 50%of the total distance it should execute.
325
+
326
+
You can use delay and duration at the same time, if you set delay to 50% and set the animation to 50%, it will start at the half of the component and will last half of the time it should last. That means, if you set a delay, duration will use the total distance between the delay and the end of the component as reference.
327
+
328
+
So, let's say we are using a component of 1000px, middle as anchor and we set duration and delay as 50.
329
+
330
+
The animation won't start until the center of the screen (middle anchor) is at the center of the component (500px). So the total distance from delay to the end of the component is 500px. We also setted a duration at half, so the animation should last as half of the total distance, at 250pxof the end of the component the animation will finish.
331
+
332
+
### Recommendations
333
+
334
+
If you struggle trying to understand that. I mean it could be hard to understand with all those numbers and calculations.
335
+
336
+
I recommend to experiment with those values. Just go and mess around with it, maybe you'll understand it better if you see how it behaves.
0 commit comments