Laravel Breeze 悬停下拉菜单
Dropdown on hover for Laravel Breeze dropdown
我已经使用 Laravel Breeze 设置了一个项目,并且正在使用其中的一些默认组件。其中之一是导航栏中使用的下拉组件。默认情况下,您需要单击下拉菜单才能使菜单显示在下方。但是,我想修改此组件,使菜单在悬停时显示,如果您只需单击下拉菜单 link,它就会带您到另一个页面。
这是有问题的下拉组件:
@props(['align' => 'right', 'width' => '48', 'contentClasses' => 'py-1 bg-blue-light'])
@php
switch ($align) {
case 'left':
$alignmentClasses = 'origin-top-left left-0';
break;
case 'top':
$alignmentClasses = 'origin-top';
break;
case 'right':
default:
$alignmentClasses = 'origin-top-right right-0';
break;
}
switch ($width) {
case '48':
$width = 'w-48';
break;
}
@endphp
<div class="relative m-auto" x-data="{ open: false }" @click.away="open = false" @close.stop="open = false">
<div @click="open = ! open">
{{ $trigger }}
</div>
<div x-show="open"
x-transition:enter="transition ease-out duration-200"
x-transition:enter-start="transform opacity-0 scale-95"
x-transition:enter-end="transform opacity-100 scale-100"
x-transition:leave="transition ease-in duration-75"
x-transition:leave-start="transform opacity-100 scale-100"
x-transition:leave-end="transform opacity-0 scale-95"
class="absolute z-50 mt-2 {{ $width }} rounded-md shadow-lg {{ $alignmentClasses }}"
style="display: none;"
@click="open = false">
<div class="rounded-md ring-1 ring-black ring-opacity-5 {{ $contentClasses }}">
{{ $content }}
</div>
</div>
</div>
知道如何修改它以使其按照我想要的方式运行吗?
这可以通过使用 Vue JS 中的 @mouseover
和 @mouseleave
来实现,分别用于打开和关闭菜单。更新后的代码如下所示:
<div class="relative m-auto" x-data="{ open: false }" @mouseover="open = true" @mouseleave="open = false">
<div>
{{ $trigger }}
</div>
<div x-show="open"
x-transition:enter="transition ease-out duration-200"
x-transition:enter-start="transform opacity-0 scale-95"
x-transition:enter-end="transform opacity-100 scale-100"
x-transition:leave="transition ease-in duration-75"
x-transition:leave-start="transform opacity-100 scale-100"
x-transition:leave-end="transform opacity-0 scale-95"
class="absolute z-50 mt-2 {{ $width }} rounded-md shadow-lg {{ $alignmentClasses }}"
style="display: none;"
>
<div class="rounded-md ring-1 ring-black ring-opacity-5 {{ $contentClasses }}">
{{ $content }}
</div>
</div>
</div>
我已经使用 Laravel Breeze 设置了一个项目,并且正在使用其中的一些默认组件。其中之一是导航栏中使用的下拉组件。默认情况下,您需要单击下拉菜单才能使菜单显示在下方。但是,我想修改此组件,使菜单在悬停时显示,如果您只需单击下拉菜单 link,它就会带您到另一个页面。
这是有问题的下拉组件:
@props(['align' => 'right', 'width' => '48', 'contentClasses' => 'py-1 bg-blue-light'])
@php
switch ($align) {
case 'left':
$alignmentClasses = 'origin-top-left left-0';
break;
case 'top':
$alignmentClasses = 'origin-top';
break;
case 'right':
default:
$alignmentClasses = 'origin-top-right right-0';
break;
}
switch ($width) {
case '48':
$width = 'w-48';
break;
}
@endphp
<div class="relative m-auto" x-data="{ open: false }" @click.away="open = false" @close.stop="open = false">
<div @click="open = ! open">
{{ $trigger }}
</div>
<div x-show="open"
x-transition:enter="transition ease-out duration-200"
x-transition:enter-start="transform opacity-0 scale-95"
x-transition:enter-end="transform opacity-100 scale-100"
x-transition:leave="transition ease-in duration-75"
x-transition:leave-start="transform opacity-100 scale-100"
x-transition:leave-end="transform opacity-0 scale-95"
class="absolute z-50 mt-2 {{ $width }} rounded-md shadow-lg {{ $alignmentClasses }}"
style="display: none;"
@click="open = false">
<div class="rounded-md ring-1 ring-black ring-opacity-5 {{ $contentClasses }}">
{{ $content }}
</div>
</div>
</div>
知道如何修改它以使其按照我想要的方式运行吗?
这可以通过使用 Vue JS 中的 @mouseover
和 @mouseleave
来实现,分别用于打开和关闭菜单。更新后的代码如下所示:
<div class="relative m-auto" x-data="{ open: false }" @mouseover="open = true" @mouseleave="open = false">
<div>
{{ $trigger }}
</div>
<div x-show="open"
x-transition:enter="transition ease-out duration-200"
x-transition:enter-start="transform opacity-0 scale-95"
x-transition:enter-end="transform opacity-100 scale-100"
x-transition:leave="transition ease-in duration-75"
x-transition:leave-start="transform opacity-100 scale-100"
x-transition:leave-end="transform opacity-0 scale-95"
class="absolute z-50 mt-2 {{ $width }} rounded-md shadow-lg {{ $alignmentClasses }}"
style="display: none;"
>
<div class="rounded-md ring-1 ring-black ring-opacity-5 {{ $contentClasses }}">
{{ $content }}
</div>
</div>
</div>