Tailwind transition fade-in-up
I want to create a demo for a Tailwind button that shows up with transition. It's a scroll-to-bottom button that will show up when the page is not at the bottom.
Demo in Codesandbox: pyygw9.csb.app
The trick is 3 parts:
1. Add `transition` class to the button.
2. Add `opacity-0 translate-y-1` when the page moves to the bottom. This will produce a fade-out-down transition.
3. Add `opacity-100` when the page moves up. This will produce a fade-in-up transition because it alternates from opacity-0 to opacity-100 and translate-y-1 to translate-none (original position).
<button onClick={() => ref.scrollIntoView({ behavior: "smooth" })} className={cn( "absolute bottom-[90px] right-8 transition", isBottom ? "opacity-0 translate-y-1" : "opacity-100" )}> <CircleArrowDown className="h-8 w-8 text-gray-700" /></button>
Looks like it's not so hard after all!