icon

四角がanimation

chatGPT
loading
chatGPT
更新日:

四角がanimation

<html>
  <head>
    <title>%title%</title>
    %style("main.css")%
    %script("main.js")%
  </head>
  <body>
    <div class='container'>
     <div class="box-container">
    <div class="box">
    <div class="face front"></div>
    <div class="face back"></div>
    <div class="face top"></div>
    <div class="face bottom"></div>
    <div class="face left"></div>
    <div class="face right"></div>
  </div>
</div>

    </div>
  </body>
</html>
body {
  margin: 0px;
}

.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-size: cover;
  background-position: center center;
  width: 100%;
  height: 100%;
  
  color: white;
  text-shadow: 1px 1px 2px #000;
}

.box-container {
  width: 200px;
  height: 200px;
  perspective: 800px;
}

.box {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 256ms;
}

.face {
  position: absolute;
  width: 100%;
  height: 100%;
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.2);
  background-color: white;
  border: 2px solid black;
}

.front {
  transform: translateZ(100px);
   background-image: linear-gradient(to bottom right, #ff416c, #ff4b2b);
}

.back {
  transform: translateZ(-100px);
  background-image: linear-gradient(to top left, #003973, #95B3D7);
}

.top {
  transform: rotateX(90deg) translateZ(-100px);
  background-image: linear-gradient(to top, #008CBA, #B4E4FE);
}

.bottom {
  transform: rotateX(-90deg) translateZ(-100px);
  background-image: linear-gradient(to bottom, #ff416c, #ff4b2b);
}

.left {
  transform: rotateY(-90deg) translateZ(-100px);
   background-image: linear-gradient(to left, #DC143C, #FFB6C1);
}

.right {
  transform: rotateY(90deg) translateZ(-100px);
  background-image: linear-gradient(to right, #800080, #BA55D3);
}

.box:hover {
  transform: rotateX(0deg) rotateY(0deg);
}
window.addEventListener('load', () => {
  let message = 'Hello, Runstant!';
  console.log(message);
  console.log(55*54)
  const box = document.querySelector('.box');

box.addEventListener('mousemove', e => {
  const boxWidth = box.clientWidth;
  const boxHeight = box.clientHeight;
  const mouseX = e.offsetX;
  const mouseY = e.offsetY;
  const rotateY = (mouseX / boxWidth - 0.5) * 128;
  const rotateX = (mouseY / boxHeight - 0.5) * 128;
  box.style.transform = rotateX(${rotateX}deg) rotateY(${rotateY}deg);
});

});