javascript - 使用 Tailwind CSS 使用来自 `@headlessui/react` 的`Transition` 创建自上而下的幻灯片动画
问题描述
我想创建以下效果:
目前,我有这个奇怪的效果:
我正在使用从.@headlessui/react
我的代码如下所示:
<Transition
show={app.theme !== 'light'}
enter="transition ease duration-700 transform"
enterFrom="opacity-0 -translate-y-full"
enterTo="opacity-100 translate-y-0"
leave="transition ease duration-1000 transform"
leaveFrom="opacity-100 translate-y-0"
leaveTo="opacity-0 -translate-y-full"
>
我如何实现它?
解决方案
我解决了。它不会在 Codesandbox 上显示动画,因为 Tailwind 动画在 Codesandbox 上不起作用(这是他们的错误),但代码已在本地测试并且运行良好。
{theme.type !== "light" && theme.color !== null && (
<div
className={`mt-4 mx-2 flex items-center space-x-2 transition-all ease-out duration-700 h-10 ${
isDarkTheme ? "opacity-100" : "opacity-0"
}`}
>
<label className="flex items-center justify-between w-1/2 h-full px-4 py-6 text-lg font-medium leading-4 text-gray-400 border-2 border-gray-800 bg-gray-800 rounded-md cursor-pointer">
<span>Dim</span>
<input
type="radio"
name="darkOption"
className="w-4 h-4"
value="dim"
checked={theme.color === "dim"}
onChange={() => {
updateTheme({
color: "dim",
})
}}
/>
</label>
<label className="flex items-center justify-between w-1/2 h-full px-4 py-6 text-lg font-medium leading-4 text-gray-400 border-2 border-gray-800 rounded-md cursor-pointer bg-black">
<span>Lights Out</span>
<input
type="radio"
name="darkOption"
className="w-4 h-4"
value="lights-out"
checked={theme.color === "lights-out"}
onChange={() => {
updateTheme({
color: "lights-out",
})
}}
/>
</label>
</div>
)}
Codesandbox → https://codesandbox.io/s/headless-ui-theme-animated-cbft1
推荐阅读
- python - 对 Python 很陌生,如何为这个测试编写代码?
- azure - Azure CLI 查询 JMESPATH 多个表达式
- python - 如何使用 Faust Python 包将 kafka 主题与 Web 端点连接起来?
- vba - 如何在 vba 的类中的 Let 函数上设置 2 个参数(对于 excel)?
- node.js - Firebase 云功能服务器错误。getaddrinfo ENOTFOUND storage.googleapis.com
- javascript - 添加日志以存储有关用户操作 JavaScript 的信息
- javascript - 如何在图中找到元素?
- c++ - 错误 C2678:未找到采用“const_Ty”类型的左操作数的运算符(或没有可接受的转换)
- linux - 安装 .run 文件期间的浮点异常(核心转储)
- azure - ASP.Net Core 3.1 在 Azure 应用服务上加载 Azure Key Vault 时出错