Skip to content
nikitaourazbaevPublic

About

Alpine plugin to run JavaScript when elements are shown or hidden with `x-show`

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

x-shown

This is a plugin for Alpine.js that adds two directives that work with x-show: x-shown and x-hidden. The code in these directives is run when the element has been shown or hidden.

Works with and without transitions.

Example:

<div
  x-show="open"
  x-shown="console.log('shown', $el)"
  x-hidden="console.log('hidden', $el)"
></div>

Add the directives to an element that has x-show.

Installation

As a module

npm install x-shown
import Alpine from 'alpinejs';
import shown from 'x-shown';

Alpine.plugin(shown);

window.Alpine = Alpine;

Alpine.start();

From a CDN

<html>
  <head>
    ...
    <!-- Alpine Plugins -->
    <script
      defer
      src="https://cdn.jsdelivr.net/npm/x-shown@1.x.x/dist/cdn.min.js"
    ></script>
    <!-- Alpine Core -->
    <script
      defer
      src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"
    ></script>
  </head>
  ...
</html>

About

Alpine plugin to run JavaScript when elements are shown or hidden with `x-show`

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages