Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="root"></div>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Catamaran:wght@700&family=Fascinate+Inline&family=Poppins:wght@300;400;600;700&family=Roboto:wght@400;500;700;900&display=swap");

*,
*::before,
*::after {
  box-sizing: inherit;
}

*::selection {
  background: none;
}

html {
  box-sizing: border-box;
  font-size: 62.5%;
}

body {
  margin: 0;
  padding: 0;
  font-family: "Roboto", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.6;
}

.App {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
}

.container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 1280px;
}

.card {
  display: flex;
  width: 86.4rem;
  border-radius: 8px;
  padding: 40px;
  background: linear-gradient(to right, #016070, #002a3d);

  &__image-box {
    flex: 0 0 29.5rem;
    margin-left: 6.9rem;
  }

  &__image {
    height: 274px;
    border-radius: 8px;
    transform-origin: center;
  }

  &__info {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  &__genre {
    font-size: 1.4rem;
    text-transform: uppercase;
    color: rgba(#fff, 0.6);
    font-weight: 600;
  }

  &__rating-box {
    display: flex;
    align-items: center;
    font-size: 1.4rem;
    color: #fff;
  }

  &__icon {
    width: 1.6rem;
    height: 1.6rem;
    margin-right: 0.8rem;
  }

  &__title {
    margin-top: 0.4rem;
    margin-bottom: 2.4rem;
    font-size: 3.6rem;
    font-weight: 700;
    color: #fff;
  }

  &__description {
    margin-bottom: 3.2rem;
    font-size: 1.6rem;
    color: #e2e2e2;
    line-height: 1.8;
  }

  &__actions {
    display: flex;
    align-items: center;
    gap: 2.4rem;
  }

  &__button {
    border: none;
    border-radius: 8px;
    padding: 1.6rem 2.4rem;
    font-size: 1.4rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    cursor: pointer;
    color: #fff;
    background-color: none;
    background: linear-gradient(
      135deg,
      #d6379b 25%,
      #d136c1 50%,
      #9434a4 75%,
      #84309d
    );
    background-size: 200%;
    background-position: 0%;
    transition: all 0.2s ease-in-out;

    &:hover {
      background-position: 50%;
    }

    &:active {
      background-position: 100%;
    }
  }

  &__link {
    border-bottom: 1px solid transparent;
    padding-bottom: 2px;
    font-size: 1.4rem;
    letter-spacing: 1px;
    text-decoration: none;
    color: rgba(#fff, 0.7);
    transition: all 0.2s ease;

    &:hover {
      color: rgba(#fff, 0.9);
    }
  }
}

.faded {
  opacity: 0.5;
}

.arrow {
  width: 4rem;
  height: 4rem;
  opacity: 0.7;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  transition: all 0.2s ease;

  &:hover {
    opacity: 0.4;
  }

  &--left {
    left: 10%;
  }

  &--right {
    right: 10%;
  }
}

              
            
!

JS

              
                interface Movie {
  genre: string;
  title: string;
  description: string;
  imgSrc: string;
  rating: string;
  reviewCount: number;
  backgroundColor: string;
}

const seed: Movie[] = [
  {
    genre: "Sci-Fi",
    title: "TRON: Legacy",
    description:
      "The son of a virtual world designer goes looking for his father and ends up inside the digital world that his father designed. He meets his father's corrupted creation and a unique ally who was born inside the digital world.",
    imgSrc: "https://i.ibb.co/dJpPbYY/poster-1.jpg",
    rating: "6.8",
    reviewCount: 42,
    backgroundColor: "linear-gradient(to right, #016070, #002a3d)"
  },
  {
    genre: "Crime",
    title: "Kiss Kiss Bang Bang",
    description:
      "After being mistaken for an actor, a New York thief is sent to Hollywood to train under a private eye for a potential movie role, but the duo are thrown together with a struggling actress into a murder mystery.",
    imgSrc: "https://i.ibb.co/jyXbTrR/poster-2.jpg",
    rating: "7.5",
    reviewCount: 11,
    backgroundColor: "linear-gradient(to right, #3C8FC2, #282E82)"
  },
  {
    genre: "Drama",
    title: "The Social Network",
    description:
      "As Harvard student Mark Zuckerberg creates the social networking site that would become known as Facebook, he is sued by the twins who claimed he stole their idea, and by the co-founder who was later squeezed out.",
    imgSrc: "https://i.ibb.co/dJM43RK/poster-3.jpg",
    rating: "7.7",
    reviewCount: 27,
    backgroundColor: "linear-gradient(to right, #423330, #171A23)"
  }
];

const { useLayoutEffect, useState, useRef } = React;

interface MovieCardProps {
  movies: Movie[];
}

const tl = gsap.timeline();

const MovieCard = ({ movies }: MovieCardProps): JSX.Element => {
  const [index, setIndex] = useState<number>(0);
  const [isAnimating, setIsAnimating] = useState<boolean>(false);
  const cardRef = useRef<HTMLDivElement>(null);
  const imageRef = useRef<HTMLImageElement>(null);
  const contentRef = useRef<HTMLDivElement>(null);

  useLayoutEffect(() => {
    gsap.to(imageRef.current, {
      duration: 0,
      scale: 1.7,
      y: 14
    });
    gsap.to(cardRef.current, {
      duration: 0,
      background: movies[index].backgroundColor
    });
  }, [index, movies]);

  const handleClick = (direction: "left" | "right") => {
    setIsAnimating(true);

    let newIndex: number = 0;

    if (direction === "left") {
      newIndex = index - 1;
      if (newIndex < 0) {
        newIndex = 2;
      }
    } else if (direction === "right") {
      newIndex = index + 1;
      if (newIndex > 2) {
        newIndex = 0;
      }
    }

    tl.to(imageRef.current, {
      duration: 0.8,
      scale: 1.7,
      opacity: 0,
      ease: `Power3.easeOut`,
      onComplete() {
        setIndex(() => newIndex);
      }
    })
      .to(
        contentRef.current,
        {
          duration: 0.8,
          y: 10,
          opacity: 0,
          ease: "Power3.easeOut"
        },
        "-=0.8"
      )
      .to(
        cardRef.current,
        {
          duration: 1,
          ease: "Power3.easeOut",
          background: movies[newIndex].backgroundColor
        },
        "-=0.8"
      )
      .to(imageRef.current, {
        duration: 0.8,
        scale: 1.7,
        y: 14,
        opacity: 1,
        ease: "Power3.easeOut"
      })
      .to(
        contentRef.current,
        {
          duration: 0.8,
          y: 0,
          opacity: 1,
          ease: "Power3.easeOut",
          onComplete() {
            setIsAnimating(false);
          }
        },
        "-=0.8"
      );
  };

  return (
    <div className="container">
      <svg
        onClick={!isAnimating ? () => handleClick("left") : () => {}}
        xmlns="http://www.w3.org/2000/svg"
        className="arrow arrow--left"
        fill="none"
        viewBox="0 0 24 24"
        stroke="currentColor"
      >
        <path
          strokeLinecap="round"
          strokeLinejoin="round"
          strokeWidth="2"
          d="M15 19l-7-7 7-7"
        />
      </svg>
      <svg
        onClick={!isAnimating ? () => handleClick("right") : () => {}}
        xmlns="http://www.w3.org/2000/svg"
        className="arrow arrow--right"
        fill="none"
        viewBox="0 0 24 24"
        stroke="currentColor"
      >
        <path
          strokeLinecap="round"
          strokeLinejoin="round"
          strokeWidth="2"
          d="M9 5l7 7-7 7"
        />
      </svg>
      <div ref={cardRef} className="card">
        <div className="card__image-box">
          <img
            ref={imageRef}
            className="card__image"
            src={movies[index].imgSrc}
            alt="TRON movie poster"
          />
        </div>
        <div ref={contentRef} className="card__content">
          <div className="card__info">
            <div className="card__genre">{movies[index].genre}</div>
            <div className="card__rating-box">
              <svg
                className="card__icon"
                xmlns="http://www.w3.org/2000/svg"
                width="16.5"
                height="15.321"
                viewBox="0 0 16.5 15.321"
              >
                <path
                  id="Icon_ionic-ios-star"
                  data-name="Icon ionic-ios-star"
                  d="M18.124,8.679H12.706L11.06,3.765a.6.6,0,0,0-1.12,0L8.294,8.679H2.839a.591.591,0,0,0-.589.589.433.433,0,0,0,.011.1.566.566,0,0,0,.247.416l4.453,3.138L5.252,17.89a.591.591,0,0,0,.2.663.57.57,0,0,0,.331.144.722.722,0,0,0,.368-.133l4.346-3.1,4.346,3.1a.69.69,0,0,0,.368.133.529.529,0,0,0,.328-.144.584.584,0,0,0,.2-.663l-1.709-4.968,4.416-3.167.107-.092a.563.563,0,0,0-.435-.983Z"
                  transform="translate(-2.25 -3.375)"
                  fill="#ccb833"
                />
              </svg>
              <span className="card__rating">
                {movies[index].rating}
                <span className="faded"> / 10</span>
              </span>
            </div>
          </div>
          <h1 className="card__title">{movies[index].title}</h1>
          <p className="card__description">{movies[index].description}</p>
          <div className="card__actions">
            <button className="card__button">Stream Now</button>
            <a href="#!" className="card__link">
              Reviews ({movies[index].reviewCount})
            </a>
          </div>
        </div>
      </div>
    </div>
  );
};

const App = (): JSX.Element => {
  return (
    <div className="App">
      <MovieCard movies={seed} />
    </div>
  );
};

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById("root")
);

              
            
!
999px

Console