Waqar H. Syed

Before after comparison

Component 30

About

An interactive split-screen image comparison slider with a draggable dividing handle, quick toggle tabs, and keyboard navigation. Useful in photo editing portfolios, product redesigns, and color grading case studies.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Before after comparison to your project and fits it to your theme.

Code

How Before after comparison is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import * as React from "react";
import Component, { type Props, type State } from "@/components/ui/before-after-comparison";

const settings = { title: "A different point of view." };
export const loopDuration = 6;

// Pure timeline: export frame n by passing n / 60. No timers or network calls.
export function showcase(time: number): State {
  const t = ((time % loopDuration) + loopDuration) % loopDuration;
  return { reveal: 50 + 38 * Math.sin((t / 6) * Math.PI * 2) };
}

export default function Demo(props: any = {}) {
  const { showcaseTime, ...incoming } = props;
  const merged = { ...settings, ...incoming };
  return (
    <div className="w-full min-h-[460px] flex items-center justify-center p-4 sm:p-6 bg-background">
      <Component
        {...merged}
        state={showcaseTime === undefined ? incoming.state : showcase(showcaseTime)}
        seeking={showcaseTime !== undefined || incoming.seeking}
      />
    </div>
  );
}

More by Waqar H. Syed

View all
  • Build Pipeline

    Build Pipeline

    146
  • Scroll animated timeline

    Scroll animated timeline

    110
  • Focus City

    Focus City

    109
  • Storage District

    Storage District

    64
  • Thumbnail image viewer

    Thumbnail image viewer

    40
  • Glowing Pricing Tiers

    Glowing Pricing Tiers

    39
  • Featured Project Hero

    Featured Project Hero

    28
  • Donut Breakdown

    Donut Breakdown

    12