Last active
July 16, 2024 09:11
-
-
Save DenisKramer/1054e44e09d73e5aaaddb67abcbce73d to your computer and use it in GitHub Desktop.
Parallax plugin for tailwindcss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Provides a tailwindcss plugin for parallax effects. | |
| Usage: | |
| 1. Define class names for background images in the themes section of tailwind.config.ts | |
| 2. Use parralax effect on element: | |
| <div className="parallax-my-background w-screen h-screen"></div> | |
| */ | |
| import type { Config } from "tailwindcss"; | |
| const plugin = require('tailwindcss/plugin') | |
| const config: Config = { | |
| theme: { | |
| extend: { | |
| backgroundImage: { | |
| "my-background": "<background-image definition here> | |
| }, | |
| }, | |
| }, | |
| plugins: [ | |
| plugin(function({matchUtilities, theme}) { | |
| matchUtilities( | |
| { | |
| parallax: (value) => ({ | |
| backgroundImage: value, | |
| backgroundAttachment: 'fixed', | |
| backgroundPosition: 'center', | |
| backgroundRepeat: 'no-repeat', | |
| backgroundSize: 'cover' | |
| }) | |
| }, | |
| { values: theme('backgroundImage') } | |
| ) | |
| }) | |
| ], | |
| }; | |
| export default config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment