我如何使用 bootstrap transition .collapsing 与 Blazor

How can I use bootstrap transition .collapsing with Blazor

Here 是具有短过渡的折叠元素的简单示例。 (前两个蓝色按钮。)

这是我的HTML

<p>
    <a class="btn btn-primary" @onclick="ToggleDropdown" data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
        Link with href
    </a>
</p>
<div class="collapse @DropdownCssClass" id="collapseExample">
    <div class="card card-body">
        Anim pariatur cliche...
    </div>
</div>

这是代码

@code {
    private bool isDropdownVisible = true;
    private string DropdownCssClass => isDropdownVisible ? "collapsing" : "show";
    private void ToggleDropdown()
    {
        isDropdownVisible = !isDropdownVisible;
    }
}

div崩溃但没有过渡。如何应用转换?

谢谢

css-tricks.com的帮助下,我使用以下代码应用了转换

HTML

<p>
    <a class="btn btn-primary" @onclick="ToggleDropdown" data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
        Link with href
    </a>
</p>
<div class="transition-visible @DropdownCssClass" id="collapseExample">
    <div class="card card-body">
        Anim pariatur cliche...
    </div>
</div>

C#

@code { private bool isDropdownVisible = false;
private string DropdownCssClass => isDropdownVisible ? "show" : "transition-collapsed";
private void ToggleDropdown()
{
    isDropdownVisible = !isDropdownVisible;
} }

CSS

.transition-visible {
    overflow: hidden;
    transition: transform 0.3s ease-out;
    height: auto;
    transform: scaleY(1);
    transform-origin: top;
}

    .transition-visible.transition-collapsed {
        transform: scaleY(0);
    }