Skip to content

Instantly share code, notes, and snippets.

@DenisKramer
Last active July 16, 2024 09:11
Show Gist options
  • Select an option

  • Save DenisKramer/1054e44e09d73e5aaaddb67abcbce73d to your computer and use it in GitHub Desktop.

Select an option

Save DenisKramer/1054e44e09d73e5aaaddb67abcbce73d to your computer and use it in GitHub Desktop.
Parallax plugin for tailwindcss
/*
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