【问题标题】:Create top-down slide animation using `Transition` from `@headlessui/react` using Tailwind CSS使用 Tailwind CSS 使用来自 `@headlessui/react` 的`Transition` 创建自上而下的幻灯片动画
【发布时间】:2021-05-29 11:02:55
【问题描述】:

我想创建如下效果:

目前,我有这个奇怪的效果:

我正在使用来自@headlessui/reactTransition

我的代码如下:

<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"
>

如何实现?

【问题讨论】:

  • 你能提供一个包含你目前拥有的代码框吗?
  • @TiagoCoelho 已经找到了解决方案。很快就会发布:)

标签: javascript html reactjs tailwind-css


【解决方案1】:

我解决了。它不会在 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>
)}

代码沙盒 → https://codesandbox.io/s/headless-ui-theme-animated-cbft1

【讨论】:

  • 其实你没有用幻灯片动画解决你原来的问题。它只是不透明。
  • @DanielSzy 你能发布解决方案吗?除非我使用不透明度,否则它无论如何都会重叠,所以我不知道有什么问题。无论如何,我会喜欢你的解决方案:)
  • 我花了一段时间才弄明白,我为我的用例找到了这个库和示例:framer.com/docs/examples/#shared-layout-animations :)
  • 哦,太好了,这很棒。如果我以这种方式使用它,我会更新答案:)
猜你喜欢
  • 2019-01-26
  • 1970-01-01
  • 2019-10-05
  • 2011-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-17
相关资源
最近更新 更多