DocumentationSine Wave

Sine Wave

An animated display of items arranged in a sine wave pattern. Each item bounces into position with a spring animation, creating a playful wave effect.

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7

Install using CLI

npx shadcn@latest add "https://obsidianui.dev/r/sine-wave.json"

Install Manually

1

Install dependencies

npm install framer-motion clsx tailwind-merge
2

Copy the source code

Copy into components/ui/sine-wave.tsx

import React from 'react';
import { motion } from 'framer-motion';
import Image from 'next/image';
import { cn } from '@/lib/utils';
 
const SineWave = ({
  items,
  amplitude = 100,
  frequency = 5,
  shouldAnimate = true,
  itemClassName = ''
}: {
  items: { image: string }[];
  amplitude?: number;
  frequency?: number;
  shouldAnimate?: boolean;
  itemClassName?: string;
}) => {
  return (
    <div className="w-full h-96 flex items-center justify-center overflow-hidden">
      <div className="flex items-center justify-center gap-4 relative">
        {items.map((item, index) => {
          const yd = Math.sin((index * Math.PI) / frequency) * amplitude;
 
          return (
            <motion.div
              key={`sine-wave-${index}`}
              className="relative"
              initial={{
                opacity: shouldAnimate ? 0 : 1,
                y: shouldAnimate ? 0 : yd
              }}
              animate={{ opacity: 1, y: yd }}
              transition={{
                duration: 0.8,
                type: 'spring',
                bounce: 0.5,
                delay: index * 0.05
              }}
            >
              <div className={cn(`w-20 h-20 rounded-xl overflow-hidden`, itemClassName)}>
                <Image
                  src={item.image}
                  alt={`Item ${index + 1}`}
                  width={64}
                  height={64}
                  className="w-full h-full object-cover"
                />
              </div>
            </motion.div>
          );
        })}
      </div>
    </div>
  );
};
 
export default SineWave;

Props

Prop NameTypeDefaultDescription
items{ image: string }[]-Array of items with image URLs
amplitudenumber100Height of the wave peaks
frequencynumber5Frequency of the sine wave
shouldAnimatebooleantrueEnable entrance animation
itemClassNamestring''Additional classes for items