Dropdown animation
Dropdown menu effect using Tailwind and Alpine
1
<div class="bg-gray-200 flex min-h-screen items-center ml-32">
2
<div class="inline-block relative" x-data="{open: false}">
3
<button @click="open = !open" class="focus:outline-none shadow cursor-pointer inline-block text-gray-700 hover:text-black flex border border-gray-400 rounded p-2 pl-3 pr-1 bg-gray-100" :class="{ 'shadow-none border-indigo-300': open}">
4
@snapey
5
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" :class="{'rotate-180': open}" class="ml-1 transform duration-300 inline-block fill-current text-gray-500 w-6 h-6"><path fill-rule="evenodd" d="M15.3 10.3a1 1 0 011.4 1.4l-4 4a1 1 0 01-1.4 0l-4-4a1 1 0 011.4-1.4l3.3 3.29 3.3-3.3z"/></svg>
6
</button>
7
8
<ul x-show="open" class="bg-white absolute left-0 shadow w-40 rounded text-indigo-600 origin-top shadow-lg"
9
x-transition:enter="transition ease-out duration-200"
10
x-transition:enter-start="opacity-0 transform scale-y-50"
11
x-transition:enter-end="opacity-100 transform scale-y-100"
12
x-transition:leave="transition ease-in duration-300"
13
x-transition:leave-end="opacity-0 transform scale-y-50"
14
>
15
<li><a href="#" class="py-1 px-3 block hover:bg-indigo-100">Profile</a></li>
16
<li><a href="#" class="py-1 px-3 border-b block hover:bg-indigo-100">Billing</a></li>
17
<li><a href="#" class="py-1 px-3 block hover:bg-indigo-100">Log out</a></li>
18
</ul>
19
</div>
20
</div>
Copied!
Last modified 1yr ago
Copy link