Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to animate the css zoom property

Is it possible to get a smooth transition for the css zoom property?

I googled a lot, but the results for the keywords "css" and "zoom" are always about transform and transition. So, I don't want to know how to do it with transform and scale and so on. Just with the css zoom property.

document.querySelector('div').addEventListener('click', function(e) {
  e.target.classList.toggle('zoom');
});
div {
  width: 50px;
  height: 50px;
  background: red;
  cursor: pointer;
}

.zoom {
  zoom: 200%;
}
<div>click me!</div>
like image 213
Max Avatar asked Nov 04 '25 13:11

Max


1 Answers

Non-standard This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The non-standard zoom CSS property can be used to control the magnification level of an element. transform: scale() should be used instead of this property, if possible. However, unlike CSS Transforms, zoom affects the layout size of the element.

MDN

So, you can use scale for this.

document.querySelector('div').addEventListener('click', function(e) {
  e.target.classList.toggle('zoom');
});
div {
  width: 50px;
  height: 50px;
  background: red;
  cursor: pointer;
  transition:.5s;
  transform-origin:left top;
}

.zoom {
  transform:scale(2);
}
<div>click me!</div>
like image 90
doğukan Avatar answered Nov 06 '25 03:11

doğukan