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

              
                <div class="box" id="box"></div>

<div class="controls-grid">
  <button onclick="scaleUp()">➕ Увеличить</button>
  <button></button>
  <button onclick="scaleDown()">➖ Уменьшить</button>

  <button></button>
  <button onclick="move('up')">↑ Вверх</button>
  <button></button>

  <button onclick="move('left')">← Влево</button>
  <button class="reset" onclick="reset()">🔄 Сброс</button>
  <button onclick="move('right')">Вправо →</button>

  <button></button>
  <button onclick="move('down')">↓ Вниз</button>
  <button></button>

  <button onclick="rotate()">🔁 Повернуть</button>
  <button onclick="toggleSkew()">💫 Наклон</button>
  <button onclick="toggleOpacity()">🌫 Прозрачность</button>
</div>
              
            
!

CSS

              
                :root {
  --rotate: 0deg;
  --scale: 1;
  --translate-x: 0px;
  --translate-y: 0px;
  --skew: 0deg;
  --opacity: 1;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: #f9f9f9;
  font-family: "Segoe UI", sans-serif;
  padding: 20px;
}

.box {
  width: 100px;
  height: 100px;
  background-color: #e6001f;
  margin-bottom: 30px;
  animation: transformAnim 0.4s ease;
  transform: rotate(var(--rotate)) scale(var(--scale))
    translate(var(--translate-x), var(--translate-y)) skewX(var(--skew));
  opacity: var(--opacity);
}

/* Красивая анимация для всех изменений */
@keyframes transformAnim {
  from {
    transform: rotate(var(--prev-rotate)) scale(var(--prev-scale))
      translate(var(--prev-x), var(--prev-y)) skewX(var(--prev-skew));
    opacity: var(--prev-opacity);
  }
  to {
    transform: rotate(var(--rotate)) scale(var(--scale))
      translate(var(--translate-x), var(--translate-y)) skewX(var(--skew));
    opacity: var(--opacity);
  }
}

/* Кнопки */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 600px;
}

button {
  padding: 10px 14px;
  font-size: 14px;
  border: none;
  border-radius: 8px;
  background-color: #e0e0e0;
  color: #333;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

button:hover {
  background-color: #c0c0c0;
}

button.reset {
  background-color: #e6001f;
  color: #fff;
}

button.reset:hover {
  background-color: #c40019;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 10px;
  justify-content: center;
  margin: 0 auto;
}

.controls-grid button {
  padding: 10px 16px;
  font-size: 14px;
  border: none;
  border-radius: 8px;
  background-color: #e0e0e0;
  color: #333;
  cursor: pointer;
  transition: background-color 0.2s ease;
  white-space: nowrap;
  min-width: 100px;
  max-width: 140px;
  box-sizing: border-box;
}

.controls-grid button:hover {
  background-color: #c0c0c0;
}

.controls-grid button:empty {
  background: transparent;
  cursor: default;
  pointer-events: none;
}

.controls-grid .reset {
  background-color: #e6001f;
  color: #fff;
}

.controls-grid .reset:hover {
  background-color: #c40019;
}
              
            
!

JS

              
                const root = document.documentElement;

let state = {
  rotate: 0,
  scale: 1,
  translateX: 0,
  translateY: 0,
  skew: 0,
  opacity: 1
};

function savePreviousValues() {
  root.style.setProperty("--prev-rotate", `${state.rotate}deg`);
  root.style.setProperty("--prev-scale", state.scale);
  root.style.setProperty("--prev-x", `${state.translateX}px`);
  root.style.setProperty("--prev-y", `${state.translateY}px`);
  root.style.setProperty("--prev-skew", `${state.skew}deg`);
  root.style.setProperty("--prev-opacity", state.opacity);
}

function applyState() {
  root.style.setProperty("--rotate", `${state.rotate}deg`);
  root.style.setProperty("--scale", state.scale);
  root.style.setProperty("--translate-x", `${state.translateX}px`);
  root.style.setProperty("--translate-y", `${state.translateY}px`);
  root.style.setProperty("--skew", `${state.skew}deg`);
  root.style.setProperty("--opacity", state.opacity);
}

function animateUpdate(callback) {
  savePreviousValues();
  callback();
  applyState();

  const box = document.getElementById("box");
  box.classList.remove("box");
  void box.offsetWidth; // перезапуск анимации
  box.classList.add("box");
}

function rotate() {
  animateUpdate(() => {
    state.rotate += 45;
  });
}

function scaleUp() {
  animateUpdate(() => {
    state.scale += 0.1;
  });
}

function scaleDown() {
  animateUpdate(() => {
    state.scale = Math.max(0.1, state.scale - 0.1);
  });
}

function move(direction) {
  const step = 20;
  animateUpdate(() => {
    if (direction === "left") state.translateX -= step;
    if (direction === "right") state.translateX += step;
    if (direction === "up") state.translateY -= step;
    if (direction === "down") state.translateY += step;
  });
}

function toggleSkew() {
  animateUpdate(() => {
    state.skew = state.skew === 0 ? 25 : 0;
  });
}

function toggleOpacity() {
  animateUpdate(() => {
    state.opacity = state.opacity === 1 ? 0.3 : 1;
  });
}

function reset() {
  animateUpdate(() => {
    state = {
      rotate: 0,
      scale: 1,
      translateX: 0,
      translateY: 0,
      skew: 0,
      opacity: 1
    };
  });
}
              
            
!
999px

Console