Logo

dev-resources.site

for different kinds of informations.

Clip-Path Circle Reveal Animation With Mouse Movement

Published at
12/3/2024
Categories
javascript
webdev
gsap
animation
Author
plsankar
Categories
4 categories in total
javascript
open
webdev
open
gsap
open
animation
open
Author
8 person written this
plsankar
open
Clip-Path Circle Reveal Animation With Mouse Movement

Whatโ€™s the Plan?

Weโ€™ll create an animation where an image is revealed through a circle that moves with your mouse. Youโ€™ll also be able to tweak the size of the circle and experiment with the behavior.

Hereโ€™s what youโ€™ll need:

  • GSAP: For buttery-smooth animations.
  • Tweakpane: For a slick UI to adjust the animation on the fly.
  • HTML & CSS: To set up and style the page.

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Clip-Path Animation</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <img 
    src="https://images.unsplash.com/photo-1696149328298-6e2f257bd45a?q=80&w=2104&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" 
    alt="Clip-path animation">
  <script src="script.js"></script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

CSS

body {
  margin: 0;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #000;
  overflow: hidden;
}

img {
  width: 100%;
  height: auto;
  clip-path: circle(var(--size, 10%) at var(--x, 50%) var(--y, 50%));
  transition: clip-path 0.6s;
}
Enter fullscreen mode Exit fullscreen mode

JS

import gsap from "https://esm.sh/gsap";

// Smooth animations
const xTo = gsap.quickTo("img", "--x", { duration: 0.6, ease: "power3" });
const yTo = gsap.quickTo("img", "--y", { duration: 0.6, ease: "power3" });
const sizeTo = gsap.quickTo("img", "--size", { duration: 0.6, ease: "power3" });

// Update based on mouse movement
window.addEventListener("mousemove", (e) => {
  xTo((e.clientX / window.innerWidth) * 100);
  yTo((e.clientY / window.innerHeight) * 100);
});

Enter fullscreen mode Exit fullscreen mode

Preview

gsap Article's
30 articles in total
Favicon
How to improve the Frontend part of the project using one button as an example :))))
Favicon
Reflections on My Coding Journey: Lessons from Recent Weeks
Favicon
Circle Cursor Js #GSAP
Favicon
"Day 7 with GSAP: Interactive Scrolling Animation with Rotating Arrows"
Favicon
GSAP ScrollTrigger animation for Upwork Client Demo
Favicon
Day 6: Text Animation with GSAP โ€“ A Split Letter Magic! ๐ŸŽจโœจ
Favicon
๐Ÿš€ Day 5: Creating a Hamburger Menu with GSAP
Favicon
Day 4: Enhancing UX with a Custom Cursor Using GSAP ๐Ÿš€๐ŸŽจ
Favicon
"Unlocking the Power of GSAP for Stunning Web Animations" ๐ŸŽจโœจ
Favicon
Preloader Animation #GSAP
Favicon
GSAP: GreenSock Animation Platform ๐Ÿš€
Favicon
Animated Carousel
Favicon
๐Ÿš€ ๐—ง๐—ต๐—ฒ๐—ฅ๐—ฒ๐—ฎ๐—น๐—›๐—ผ๐˜๐—ฒ๐—น๐˜€ ๐ŸŒŸ
Favicon
Clip-Path Circle Reveal Animation With Mouse Movement
Favicon
Getting started with Gsap!
Favicon
Todayโ€™s new knowledge #7(GSAP)
Favicon
Image Reveal Animation with HTML, CSS, and GSAP
Favicon
Easy React Animation with GSAP
Favicon
MoonAlert A CSS Animated Moon Notification Box
Favicon
Creating a Mesmerizing Moonlit Night Sky Animation with CSS
Favicon
๐Ÿš€ Motion Scape With GSAP
Favicon
Pinning Images with GSAP: A Smooth Scrolling Animation in Next.js
Favicon
Learning GSAP with a Day-to-Night Scroll Animation ๐ŸŒž๐ŸŒœ
Favicon
From Static to Stunning: Animate with GSAP
Favicon
Blurry Card with Parallax Effect ๐Ÿ’ณ
Favicon
Fun Animation using GSAP
Favicon
Future Bank Fintech Green: The Intersection of Finance and Sustainabilit
Favicon
Framer ground.
Favicon
Parallax image scroll speed with Nuxt 3 and GSAP ๐Ÿ›ฃ๏ธโœจ
Favicon
Creating Interactive Hover Effects with GSAP and SplitType

Featured ones: