1
The problem is, I have a div
centralized with that container trick (Trick) in position: absolute
or fixed
and the div
internal in relative
.
As you can see, when the animation is executed, div
internal (#square) grows from top to bottom. I wish it would grow from its center and expand everywhere, but it stays at the same distance from the top, because of the top: -30%
. What can I do to make it, in animation, it expands everywhere, rather than up down?
// Função simples para animar a div com css transitions
var square = document.querySelector('#square');
setTimeout(function(){
square.style.width = '100px';
square.style.height = '100px';
}, 500);
#container {
position: fixed;
left: 50%;
top: 50%;
}
#square {
position: relative;
left: -50%;
top: -30%;
width: 20px;
height: 20px;
background: blue;
transition: all 1s ease-in-out;
}
<div id="container" >
<div id="square" > </div>
</div>
Just be very careful with the contents of
div
. If you have some text, for example, it will be increased together.– Woss
@Andersoncarloswoss was more or less what I was going to ask. But, in this case, it’s an image. There would be no distortion in the image (if I inserted it already with the size that would be after the transition)?
– Seu Madruga
For an image works well, but it is convenient to set the url for the image to put the correct Sizes according to the image and change the transformation from Scale, from 0.x to 1
– Isac