Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/arthurdenner/use-lax

React hook to use with lax.js
https://github.com/arthurdenner/use-lax

animation hacktoberfest lax react

Last synced: 9 days ago
JSON representation

React hook to use with lax.js

Awesome Lists containing this project

README

        

# use-lax

[![npm](https://img.shields.io/npm/v/use-lax.svg)](https://www.npmjs.org/package/use-lax)
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg)](#contributors)

React hook to use with [lax.js](https://github.com/alexfoxy/lax.js).

## Usage

```javascript
import React from 'react';
import { useLax, useLaxElement } from 'use-lax';

function App() {
const [showBubble, setBubble] = useState(false);
const toggleBubble = () => setBubble(!showBubble);

// Use once in the top level element
// to configure drivers and initial elements
// https://github.com/alexfoxy/lax.js#setup
useLax({
drivers: [
{
name: 'scrollY',
getValueFn: () => window.scrollY,
},
],
});

return (



Toggle Bubble

{showBubble ? '...now scroll down...' : '^ press the button ^'}


{showBubble ? : null}

);
}

function Bubble() {
// Use it on every component added dynamically
// and provide the animation driven from the drivers
const ref = useLaxElement({
animationData: {
scrollY: {
presets: ['fadeInOut:200:0'],
translateX: [
[0, 'screenHeight'],
[0, 'screenWidth'],
],
},
},
});

return

;
}
```

- [Full example above](https://codesandbox.io/s/q9882qjxzq)
- [Lax homepage example](https://codesandbox.io/s/039krok5ml) - [HTML version](https://alexfox.dev/lax.js/)
- [Mario example](https://codesandbox.io/s/r48kz0okrm) - [HTML version](https://codesandbox.io/s/vcv4k)

## Contributors

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):



Arthur Denner

💻 🎨 📖 💡 🤔 🚧

Antoine Martin

💻

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!