Animation always play when an element from display:none to shown status. If I want style a custom checkbox. I only need it play animate when user check or uncheck it.
input[type=checkbox] { opacity: 0; } // native checkbox hidden
input[type=checkbox] ~ .mycheck {
animation: uncheck 300ms ease-out forwards; // play uncheck animate
}
input[type=checkbox]:checked ~ .mycheck {
animation: check 300ms ease-out forwards; // play checked animate
}
The issue is check
and uncheck
not only play when user click it. It play when page load also. Or when the parent element switch hidden to shown. e.g. in bootstrap tabs.
I know javascript can deal with it easily. But in fact, this issue come from an interest github project https://github.com/FezVrasta/bootstrap-material-design/issues/48. That handsome boy want implement google material design by bootstrap3.
Currently I can think of a way(not perfect). When :not(:hover)
set animation-duration: 1ms;
. Let animate ended quickly. But user still look a short flickr.
input[type=checkbox]:not(:hover) ~ .mycheck {
animation-duration: 1ms;
}
Cannot set to 0ms. otherwise animate doesn't played until user hover it.
Is there any better ways?