Given a basic HTML template and CSS style, I'm seeing two different elements react completely different.
setTimeout(function() {
document.body.id = 'animate';
}, 100);
#animate input[type="checkbox"]{
width: 100px;
height: 100px;
transition: 2s all;
-moz-appearance: none;
}
#animate div{
width: 100px;
height: 100px;
background:blue;
transition: 2s all;
}
<input type="checkbox"/>
<div></div>
If you open this in a browser, you see that, on load, the div already has its 100px height/width, yet the checkbox grows from 0px to 100px height/width over 2s.
Why does the input
behave differently than the div
? Is it because the input has default -webkit-appearance
giving it something to transition between?
PowerPoint for Microsoft 365, PowerPoint 2019 (on the PC and on macOS), and PowerPoint for the web have Morph to help you make smooth animations, transitions, and object movements across the slides in your presentation. Play.
CSS transitions provide a way to control animation speed when changing CSS properties. Instead of having property changes take effect immediately, you can cause the changes in a property to take place over a period of time.
The transition-property property specifies the name of the CSS property the transition effect is for (the transition effect will start when the specified CSS property changes). Tip: A transition effect could typically occur when a user hover over an element.
The div
's default width/height is auto and as such it won't animate.
The input
has a default width/height and as such will animate.
As a side note, the transition does work on the div
, though only animate its color, as it is possible to animate a color from transparent
to blue
You should also consider to not use all
with transition
, as it can give unpredictalbe result because of this fact that browsers does set some values on elements to a default value, where some can be animated, some can't.
So, in your case, if your intention is to animate width/height, set it up like this: transiton: width 2s ease, height 2s ease;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With