Skip to content

Instantly share code, notes, and snippets.

@diegoibanezr
diegoibanezr / alpinejs-parallax.js
Created January 16, 2025 03:01 — forked from kevnk/alpinejs-parallax.js
Parallax directive for alpinejs
/**
* Installation and setup:
* 0. Install AlpineJS: `npm i -S alpinejs`
* 1. Make sure AlpineJS is running by adding `x-data` attribute on opening `<body>` tag
* 2. Add `x-parallax="path/to/image.jpg"` on element to add parallax bg image
*
* PS. this code was partially generated from ChatGPT 4
*/
// Helper function to load an image and return its natural dimensions