I basically have an area which can be selected or deselected by clicking. It has an unselected state, which has a hover state that matches the selected state so the user gets a visual hint about clicking it.
Similarly, when selected, the hoverstate matches the unselected state.
Here's an example with selected being 'green':
.clicker { //standard state
width: 100px;
height: 100px;
background-color: red;
}
.clicker:hover {
background-color: green;
}
.green { // selected state
background-color: green;
}
.green:hover {
background-color: red;
}
The problem is, when the user clicks, it immediately turns from unselected-hover to selected-hover, so it looks sort of like they unclicked it.
I'd like to have a short period where the item maintains it's old hoverstate, that is, it's unselected (red), I hover and it turns green, I click it, jQuery in the background adds the selected/green state, but nonetheless the area stays green for a second rather than immediately going to selected hoverstate (ie showing red).
I thought about using a simple (non-)animation, something like:
@keyframes holdGreen {
0% {
background-color: green;
}
99% {
background-color: green;
}
100% {
background-color: red;
}
}
And somewhere putting
animation: holdGreen
animation-duration: 1s
and a similar holdRed for when I click a selected one to unselect.
This would work okay if it were just a class with a hover state, but it doesn't work when totally changing/adding classes which also have hover states.
Any ideas?