Reputation: 139
In this code, if you resize your screen, it'll change its size smoothly and will take a second to get there.
function f1(x) {
x.classList.toggle('fade');
}
.div {
width: 20vw;
height: 20vh;
background-color: #e50;
opacity: 1;
transition: 1000ms;
}
.fade {
opacity: 0;
}
<div class='div' onmouseover="f1(this)" onmouseout="f1(this)">
</div>
I only want the opacity to change slowly like so. Everything else should change in 0s as is default.
Upvotes: 1
Views: 31
Reputation: 43870
Add the opacity value to transition explicitly:
transition: opacity 1s
function f1(x) {
x.classList.toggle('fade');
}
.div {
width: 20vw;
height: 20vh;
background-color: #e50;
opacity: 1;
transition: opacity 1s
}
.fade {
opacity: 0;
}
<div class='div' onmouseover="f1(this)" onmouseout="f1(this)">
</div>
Upvotes: 2