Created
June 28, 2021 05:46
-
-
Save w3collective/b7e4eafa1858cc0e9138cc8eab484ebb to your computer and use it in GitHub Desktop.
Building a dropdown menu using Alpine.js
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<title>Alpine.js - Dropdown menu</title> | |
<style> | |
.rotated { | |
transform: rotate(90deg); | |
display: inline-block; | |
} | |
</style> | |
<script src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script> | |
</head> | |
<body> | |
<div x-data="{ open: false }" x-on:click.outside="open = false"> | |
<button x-on:click="open = !open">My Account <span :class="{'rotated': open}">»</span></button> | |
<ul x-show="open" x-transition.opacity> | |
<li><a href="#">Edit Profile</a></li> | |
<li><a href="#">Settings</a></li> | |
<li><a href="#">Log Out</a></li> | |
</ul> | |
</div> | |
<script src="https://unpkg.com/alpinejs@3.1.0/dist/cdn.min.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source => https://w3collective.com/dropdown-alpine-js/