Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="style.css" />
  <script src="./main.js" defer></script>
  <title>CLIP PATH</title>
</head>
<body>
  <div class="example">
    <div class="item pictureAnimation">
      <div class="pictures">
        <div class="picture">
          <img alt="Palace" src="https://picsum.photos/1000/1000?random=1" />
        </div>
        <div class="picture">
          <img alt="Philosopher" src="https://picsum.photos/1000/1000?random=2" />
        </div>
        <div class="picture">
          <img alt="Night" src="https://picsum.photos/1000/1000?random=3" />
        </div>
      </div>
      <div class="dots"></div>
      <div class="buttons">
        <button type="button"></button>
        <button type="button"></button>
      </div>
    </div>
    <div class="item clockAnimation">
      <div class="clock">
        <div class="buttonGreen"></div>
        <div class="buttonOrange"></div>
        <div class="circle">
          <div class="hand"></div>
          <div class="center"></div>
        </div>
      </div>
    </div>
  </div>
</body>
</html>
              
            
!

CSS

              
                .example {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  padding: 50px 0;
}

.item + .item{
  margin-top: 50px;
}

.pictureAnimation {
  position: relative;
  overflow: hidden;
  width: 300px;
  height: 300px;
  background-color: #1a1a1a;
  border-radius: 20px;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
}

.picture {
  position: absolute;
  inset: 0;
  clip-path: inset(110% 35% -100% round 110px);
  width: 100%;
  height: 100%;
  animation: 1.5s forwards ease-in-out;
}

.picture.start {
  clip-path: inset(15% 15% -60% round 260px);
}

.picture.slideOutUp {
  animation-name: slideOutUp;
}

.picture.slideInUp {
  animation-name: slideInUp;
  animation-delay: 0.9s;
}

.picture.slideOutDown {
  animation-name: slideOutDown;
}

.picture.slideInDown {
  animation-name: slideInDown;
  animation-delay: 0.9s;
}

.picture img {
  width: 100%;
  object-fit: cover;
}

.dots {
  position: absolute;
  right: 20px;
  top: 20px;
  width: 20px;
}

.dots .dot {
  width: 20px;
  height: 20px;
  background-color: #787878;
  border-radius: 5px;
  transition: 1s background-color 0.3s;
}

.dots .dot + .dot {
  margin-top: 10px;
}

.dots .dot.selected {
  background-color: #fff;
}

.buttons {
  position: absolute;
  right: 20px;
  bottom: 20px;
  width: 20px;
}

.buttons button {
  width: 20px;
  height: 20px;
  padding: 0;
  background-color: #fff;
  border: none;
  border-radius: 5px;
  vertical-align: top;
  cursor: pointer;
}

.buttons button:active {
  opacity: 0.8;
}

.buttons button + button {
  margin-top: 10px;
}

.buttons button::after {
  display: inline-block;
  width: 5px;
  height: 5px;
  border: solid #000;
  border-width: 2px 0 0 2px;
  rotate: 45deg;
  cursor: pointer;
  content: '';
}

.buttons button:last-child::after {
  rotate: 225deg;
  translate: 0 -2px;
}

@keyframes slideInUp {
  0% {
    clip-path: inset(110% 35% -100% round 120px);
  }
  40% {
    clip-path: inset(5% 35% 15% round 120px);
  }
  55% {
    clip-path: inset(12% 35% 8% round 120px);
  }
  70% {
    clip-path: inset(10% 35% round 120px);
  }
  100% {
    clip-path: inset(15% 15% -60% round 260px);
  }
}

@keyframes slideOutUp {
  0% {
    clip-path: inset(15% 15% -60% round 260px);
  }
  40% {
    clip-path: inset(10% 35% round 120px);
  }
  60% {
    clip-path: inset(12% 35% 8% round 120px);
  }
  100% {
    clip-path: inset(-100% 35% 110% round 120px);
  }
}

@keyframes slideInDown {
  0% {
    clip-path: inset(-100% 35% 120% round 120px);
  }
  40% {
    clip-path: inset(15% 35% 5% round 120px);
  }
  55% {
    clip-path: inset(8% 35% 12% round 120px);
  }
  70% {
    clip-path: inset(10% 35% round 120px);
  }
  100% {
    clip-path: inset(15% 15% -60% round 260px);
  }
}

@keyframes slideOutDown {
  0% {
    clip-path: inset(15% 15% -60% round 260px);
  }
  40% {
    clip-path: inset(10% 35% round 120px);
  }
  60% {
    clip-path: inset(8% 35% 12% round 120px);
  }
  100% {
    clip-path: inset(120% 35% -100% round 120px);
  }
}

.clockAnimation {
  width: 300px;
}

.clock {
  position: relative;
  width: 250px;
  height: 250px;
  padding: 25px;
  background-color: #e0d0c5;
  border-radius: 20px;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
}

.buttonGreen {
  position: absolute;
  left: 40px;
  top: -10px;
  width: 120px;
  height: 10px;
  border-radius: 10px 10px 0 0;
  background-color: #418c71;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
}

.buttonOrange {
  position: absolute;
  right: 40px;
  top: -10px;
  width: 80px;
  height: 10px;
  border-radius: 10px 10px 0 0;
  background-color: #f89334;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
}

.clock .circle {
  position: relative;
  overflow: hidden;
  width: 246px;
  height: 246px;
  background-color: #fff;
  border: 2px solid rgb(228, 208, 195);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
}

.clock .hand {
  position: absolute;
  inset: -27px;
  background-color: #418c71;
  clip-path: path("M150,0 A150,150 0,1,1 163,1 L150,150 Z");
  animation: handRotate 3s linear 1s forwards;
}

.clock .center {
  position: absolute;
  top: 100px;
  left: 100px;
  width: 40px;
  height: 40px;
  border: 3px solid #f7c17f;
  border-radius: 50%;
  background-color: #d2a46c;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
  rotate: 3deg;
  animation: centerRotate 3s linear 1s forwards;
}

.clock .center::after {
  position: absolute;
  top: -3px;
  left: 19px;
  width: 3px;
  height: 9px;
  border-radius: 4px;
  background-color: #5c4b2e;
  content: '';
}

@keyframes handRotate {
  20% {
    clip-path: path("M150,0 A150,150 0,1,1 287,90 L150,150 Z");
  }
  40% {
    clip-path: path("M150,0 A150,150 0,1,1 275,232 L150,150 Z");
  }
  60% {
    clip-path: path("M150,0 A150,150 0,1,1 136,300 L150,150 Z");
  }
  80% {
    clip-path: path("M150,0 A150,150 0,1,1 10,204 L150,150 Z");
  }
  100% {
    clip-path: path("M150,0 A150,150 0,1,1 25,67 L150,150 Z");
  }
}

@keyframes centerRotate {
  100% {
    rotate: 301deg;
  }
}

              
            
!

JS

              
                const animateClock = () => {
  let point = [125, 2];
  const radius = 150;
  const circle = document.querySelector('.circle');
  const hand = document.querySelector('.hand');

  const getClipPath = () => {
    return `path("M150,0 A150,150 0,1,1 ${point.join(',')} L150,150 Z")`
  }

  const getDistance = (value) => {
    return value < radius ? value : radius * 2 - value;
  }

  const findCircleCoordinate = (fixedValue, isLargeValue) =>{
    const center = 150;
    const delta = fixedValue - center;
    const deltaCoordinate = Math.sqrt(radius ** 2 - delta ** 2);

    return isLargeValue ? center + deltaCoordinate : center - deltaCoordinate;
  }

  circle.addEventListener('click', ({offsetX, offsetY}) => {
    point = getDistance(offsetX) >= getDistance(offsetY)
      ? [offsetX, findCircleCoordinate(offsetX, offsetY >= 150)]
      : [findCircleCoordinate(offsetY, offsetX >= 150), offsetY];
  });
}

const animatePicture = () => {
  let order = 0;
  const pictures = document.querySelector('.pictures');
  const dots = document.querySelector('.dots');
  const prevButton = document.querySelector('.buttons button:first-child');
  const nextButton = document.querySelector('.buttons button:last-child');

  for (let i = 0; i < pictures.children.length; i++) {
    const dot = document.createElement('div');
    dot.className = 'dot';
    i === order && dot.classList.add('selected');
    dots.appendChild(dot);
  }

  pictures.children[order].className = 'picture start selected';

  const changePicture = (direction) => {
    const selectedPicture = pictures.querySelector('.selected');
    const selectedDot = dots.querySelector('.selected');
    const animationDirection = direction === 'next' ? 'Up' : 'Down';

    if (direction === 'prev') {
      order = !order ? pictures.children.length - 1 : order - 1;
    } else if (direction === 'next') {
      order = order === pictures.children.length - 1 ? 0 : order + 1;
    }

    selectedPicture.className = `picture slideOut${animationDirection}`;
    pictures.children[order].className = `picture selected slideIn${animationDirection}`;

    selectedDot.className = `dot`;
    dots.children[order].className = `dot selected`;

    nextButton.disabled = true;
    prevButton.disabled = true;

    setTimeout(() => {
      selectedPicture.classList.remove(`slideOut${animationDirection}`);
      nextButton.disabled = false;
      prevButton.disabled = false;
    }, 2400);
  };

  prevButton.addEventListener('click', () => {
    changePicture('prev');
  });

  nextButton.addEventListener('click', () => {
    changePicture('next');
  });
}

animateClock();
animatePicture();
              
            
!
999px

Console