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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <div class="container">
  <div class="wedge">
    <img
      src="https://images.unsplash.com/photo-1544568100-847a948585b9?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
      alt=""
    />
  </div>
  <div class="wedge wedge--selected">
    <img
      src="https://images.unsplash.com/photo-1517423440428-a5a00ad493e8?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
      alt=""
    />
  </div>
  <div class="wedge">
    <img
      src="https://images.unsplash.com/photo-1510771463146-e89e6e86560e?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
      alt=""
    />
  </div>
  <div class="wedge">
    <img
      src="https://images.unsplash.com/photo-1507146426996-ef05306b995a?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
      alt=""
    />
  </div>
  <div class="wedge">
    <img
      src="https://images.unsplash.com/photo-1530281700549-e82e7bf110d6?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
      alt=""
    />
  </div>
  <div class="wedge">
    <img
      src="https://images.unsplash.com/photo-1548199973-03cce0bbc87b?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
      alt=""
    />
  </div>
  <div class="wedge">
    <img
      src="https://images.unsplash.com/photo-1552053831-71594a27632d?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
      alt=""
    />
  </div>
  <div class="wedge">
    <img
      src="https://images.unsplash.com/photo-1518717758536-85ae29035b6d?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
      alt=""
    />
  </div>
  <div class="wedge">
    <img
      src="https://images.unsplash.com/photo-1535930891776-0c2dfb7fda1a?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
      alt=""
    />
  </div>
  <div class="wedge">
    <img
      src="https://images.unsplash.com/photo-1504595403659-9088ce801e29?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ"
      alt=""
    />
  </div>
</div>

              
            
!

CSS

              
                :root {
  --width: 21; // this is converted to vw units using calc
  --wedge-point-l: 0;
  --wedge-point-r: 0; // these are set by js and used to clip image into wedge shape
}

body {
  position: relative;
  margin: 0;
  background: #141422;
  overflow: hidden;
}

.container {
  position: absolute;
  height: 100vh;
  width: 100%;
  left: calc(var(--width) * -0.5vw);
  margin: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  transform-origin: calc(50% + var(--width) * 0.5vw) 50%;
  animation: rotate-doge 235s linear 0s infinite;
}

.wedge {
  --rot-angle: 0deg;
  --scale: 1;
  position: absolute;
  bottom: 50%;
  left: 50%;
  margin: auto;
  width: calc(var(--width) * 1vw);
  transition: all 0.4s ease;
  transform-origin: 50% 100%;
  transform: rotate(var(--rot-angle)) scale(var(--scale));
  &,
  img,
  &:before {
    clip-path: polygon(
      var(--wedge-point-l) 0,
      var(--wedge-point-r) 0,
      var(--wedge-point-r) 0,
      50% 100%,
      var(--wedge-point-l) 0
    );
  }
  img,
  &:before {
    transition: all 0.4s ease;
    transform-origin: 50% 100%;
  }
  img {
    height: 100%;
    width: 100%;
    display: block;
    transform: translate(0, -7vw);
  }
  &:before {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    content: "";
    background: #d47;
    transform: translate(0, -2vw);
    z-index: -1;
  }
  &--selected {
    --scale: 1.4;
    &,
    img,
    &:before {
      clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 100%, 0 100%);
    }
    img {
      transform: translate(0, -0.83vw);
    }
    &:before {
      transform: translate(0, -0.22vw);
    }
  }
  &:hover img {
    opacity: 0.8;
  }
}

@keyframes rotate-doge {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(-360deg);
  }
}

              
            
!

JS

              
                function getWedgeAngle(numWedges, isSelected, otherIsSelected) {
  let ratio;
  if (isSelected) {
    ratio = 2;
  } else if (otherIsSelected) {
    ratio = (numWedges - 1) * 2;
  } else {
    ratio = numWedges;
  }
  return 360 / ratio;
}

function checkForSelected(wedges) {
  let i = 0;
  wedges.forEach(wedge => {
    i += wedge.classList.contains("wedge--selected") ? 1 : 0;
  });
  return i > 0; // return true if more than zero selected wedges
}

function update() {
  const container = document.querySelector(".container");
  const wedges = container.querySelectorAll(".wedge");
  const width = window.getComputedStyle(container).getPropertyValue("--width");
  const hasSelected = checkForSelected(wedges);
  let rotAngleDeg = 0;

  wedges.forEach((wedge, index) => {
    const isSelected = wedge.classList.contains("wedge--selected");
    
    // doing some math to get the angle for each wedge
    const wedgeAngleDeg = getWedgeAngle(wedges.length, isSelected, hasSelected);
    const wedgeHalfAngleRad = (wedgeAngleDeg * Math.PI) / 360;
    const natHeight = wedge.firstElementChild.naturalHeight;
    const natWidth = wedge.firstElementChild.naturalWidth;
    const actualHeight = (natHeight / natWidth) * width;
    const wedgeHalfWidth = actualHeight * Math.tan(wedgeHalfAngleRad);

    // setting css variables - css clip-path creates wedge shape
    wedge.style.setProperty(
      "--wedge-point-l",
      width / 2 - wedgeHalfWidth + "vw"
    );
    wedge.style.setProperty(
      "--wedge-point-r",
      width / 2 + wedgeHalfWidth + "vw"
    );
    
    // wedge rotation incorporates both the cumulative rotation and its own width, to allow it to fit between adjacent wedges even if widths are different
    wedge.style.setProperty("--rot-angle", (rotAngleDeg + wedgeAngleDeg / 2) + "deg");
    rotAngleDeg += wedgeAngleDeg;
  });
}

function setup() {
  const wedges = document.querySelectorAll(".container .wedge");
  wedges.forEach(wedge => {
    wedge.addEventListener("click", function() {
      if (wedge.classList.contains("wedge--selected")) {
        wedge.classList.remove("wedge--selected");
      } else {
        wedges.forEach(wedge => {
          wedge.classList.remove("wedge--selected");
        });
        this.classList.add("wedge--selected");
      }
      update();
    });
  });
}

setup();
setInterval(update, 600);
              
            
!
999px

Console