Gallery · 23 of 33

Circular Swap

Clip-path circle expands new image

HTML · CSS · No dependencies · MIT

HTML

<div class="circle-swap">
  <img src="https://picsum.photos/id/152/800/600" alt="Swap 1" class="c-img-1">
  <img src="https://picsum.photos/id/158/800/600" alt="Swap 2" class="c-img-2">
</div>

CSS

.circle-swap {
  position: relative;
  width: 400px;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 12px;
}

.circle-swap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* The second image starts as a zero-size circle in the center */
.circle-swap .c-img-2 {
  position: absolute;
  top: 0; left: 0;
  clip-path: circle(0% at 50% 50%);
  transition: clip-path 0.7s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 2;
}

.circle-swap:hover .c-img-2 {
  clip-path: circle(100% at 50% 50%);
}