{"id":16788750,"url":"https://github.com/markmead/alpinejs-sticky","last_synced_at":"2025-07-13T16:05:42.905Z","repository":{"id":41460044,"uuid":"458485689","full_name":"markmead/alpinejs-sticky","owner":"markmead","description":"Toggle CSS class names when an element becomes sticky to the DOM 🐙","archived":false,"fork":false,"pushed_at":"2025-03-11T13:25:37.000Z","size":29,"stargazers_count":33,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-04T02:11:17.441Z","etag":null,"topics":["alpine-js","alpinejs","alpinejs-plugin","javascript","sticky","sticky-elements"],"latest_commit_sha":null,"homepage":"https://js.hyperui.dev/examples/utility-update-class-when-sticky","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markmead.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-12T10:13:47.000Z","updated_at":"2025-03-27T23:44:31.000Z","dependencies_parsed_at":"2024-04-04T11:47:01.900Z","dependency_job_id":"e15963a6-f2fa-41db-8e94-de550f9dd442","html_url":"https://github.com/markmead/alpinejs-sticky","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/markmead/alpinejs-sticky","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-sticky","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-sticky/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-sticky/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-sticky/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markmead","download_url":"https://codeload.github.com/markmead/alpinejs-sticky/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-sticky/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265167476,"owners_count":23721450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alpine-js","alpinejs","alpinejs-plugin","javascript","sticky","sticky-elements"],"created_at":"2024-10-13T08:24:37.738Z","updated_at":"2025-07-13T16:05:42.889Z","avatar_url":"https://github.com/markmead.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Alpine JS Sticky\n\nToggle CSS class names when an element becomes sticky to the DOM 🐙\n\n## Install\n\n### With a CDN\n\n```html\n\u003cscript\n  defer\n  src=\"https://unpkg.com/alpinejs-sticky@latest/dist/sticky.min.js\"\n\u003e\u003c/script\u003e\n\n\u003cscript defer src=\"https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js\"\u003e\u003c/script\u003e\n```\n\n### With a Package Manager\n\n```shell\nnpm i -D alpinejs-sticky\n\nyarn add -D alpinejs-sticky\n```\n\n```js\nimport Alpine from 'alpinejs'\nimport sticky from 'alpinejs-sticky'\n\nAlpine.plugin(sticky)\n\nAlpine.start()\n```\n\n## Example\n\n```html\n\u003cdiv x-data\u003e\n  \u003cdiv class=\"sticky top-0 sticky-root\" x-sticky=\"!bg-red-500\"\u003e\n    \u003cp class=\"hidden\" x-sticky.sticky-root=\"!block\"\u003eHello World!\u003c/p\u003e\n  \u003c/div\u003e\n\n  \u003cp class=\"hidden\" x-sticky.sticky-root=\"!block\"\u003eHello World!\u003c/p\u003e\n\u003c/div\u003e\n```\n\n`x-sticky=\"!bg-red-500\"`\n\nThis will add `!bg-red-500` to the element when it is sticky to the DOM.\n\n`x-sticky.sticky-root=\"!block\"`\n\nThis will add `!block` to the element when the `sticky-root` element is sticky\nto the DOM.\n\nAt times you might need to apply the `! important` modifier to your CSS.\n\n_This example uses Tailwind CSS classes, but any CSS class names will work._\n\n## Modifiers\n\nAs shown you can pass a class name as a modifier to target a specific HTML\nelement.\n\nYou can also pass `wait` which will use the `scroll` event listener instead of\nthe `IntersectionObserver`. Why would you want this? Well, it comes in handy\nwhen the element is already at the top of the DOM and you don't want the stuck\nclasses applying.\n\n## Options\n\n**`x-sticky-inactive`**\n\nThis allows you to pass classes that apply to the element when it's not stuck.\nThese will be toggled alongside the active classes.\n\nUsing this means you do not need an `! important` modifier with your CSS.\n\n**`x-sticky-root`**\n\nBy default this is `-1px 0px 0px 0px`.\n\n[MDN IntersectionObserver API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API).\n\nI have removed the `x-sticky-threshold` option as I found it unnecessary through\nmy uses.\n\n### Stats\n\n![](https://img.shields.io/bundlephobia/min/alpinejs-sticky)\n![](https://img.shields.io/npm/v/alpinejs-sticky)\n![](https://img.shields.io/npm/dt/alpinejs-sticky)\n![](https://img.shields.io/github/license/markmead/alpinejs-sticky)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmead%2Falpinejs-sticky","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkmead%2Falpinejs-sticky","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmead%2Falpinejs-sticky/lists"}