<header>
  <h2 class="title">element.style.transform</h2>
  <p class="description">Змінює розташування, обертання, масштаб або нахил елемента.</p>
</header>
<main>
  <div class="result">
    <div id="interactiveBox" class="box"></div>
    <button id="rotateBtn">Обертати</button>
    <button id="scaleBtn">Масштабувати</button>
    <button id="moveBtn">Перемістити</button>
  </div>
</main>
body {
  font-size: 16px;
  line-height: 1.5;
  font-family: monospace;
}

header {
  background-color: #f1f1f1;
  margin-bottom: 25px;
  padding: 15px;
  -webkit-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  -moz-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}

header h2.title {
  padding-bottom: 15px;
  border-bottom: 1px solid #999;
}

header p.description {
  font-style: italic;
  color: #222;
}

.result {
  background-color: #f8f8f8;
  padding: 15px;
  -webkit-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  -moz-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  text-align: center;
}

.box {
  width: 100px;
  height: 100px;
  background-color: #3498db;
  margin: 0 auto;
  transition: transform 0.5s;
}

button {
  margin: 10px;
  padding: 10px 20px;
  font-size: 16px;
  cursor: pointer;
}
let rotateAngle = 0;
let scaleFactor = 1;
let translateX = 0;
let translateY = 0;

document.getElementById('rotateBtn').addEventListener('click', () => {
    rotateAngle += 45;
    updateTransform();
});

document.getElementById('scaleBtn').addEventListener('click', () => {
    scaleFactor = scaleFactor === 1 ? 1.5 : 1;
    updateTransform();
});

document.getElementById('moveBtn').addEventListener('click', () => {
    translateX += 20;
    translateY += 20;
    updateTransform();
});

function updateTransform() {
    let element = document.getElementById('interactiveBox');
    element.style.transform = `rotate(${rotateAngle}deg) scale(${scaleFactor}) translate(${translateX}px, ${translateY}px)`;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.