JSFiddle - React, Tailwind, and code Playground

by swordys

HTML

<div class='wrap'>
  <div class='item'></div>
  <div class='item'></div>
  <div class='item'></div>
  <div class='item'></div>
  <div class='item'></div>
</div>

CSS

body,
html {
  height: 100%;
  padding: 0;
  margin: 0;
}

.wrap {
  background: #eee;
  height: 100%;
  width: 100%;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10em, 18em));
  grid-gap: 20px;
  justify-content: center;
  align-items: center;
}

.item {
  background: orange;
  height: 200px;
  border: 1px solid black;
  cursor: pointer;
}

JavaScript

const box = document.querySelector('.item');
const bigBox = document.querySelector('.wrap');
const valObj = {
  x: 0,
  y: 0,
  height: 0,
  width: 0
}


box.addEventListener('click', (e) => {
  const first = e.target.getBoundingClientRect();
  const last = bigBox.getBoundingClientRect();
  const deltaX = first.left - last.left;
  const deltaY = first.top - last.top;
  const deltaW = first.width / last.width;
  const deltaH = first.height / last.height;

  bigBox.animate({
      transformOrigin: 'top left',
      transform: `
      scale(${deltaW}, ${deltaH})
      translate(${deltaX}, ${deltaY})
    `
  });



})