http://www.impressivewebs.com/css3-transitions-javascript/ This article has a demo showing how you could save animations by adding / removing a class as needed. What you could do is keep the current transition :hover
in place as a return, but for those who have JavaScript, also apply the same styles to the pseudoHover
class or something like that.
Then using JavaScript (jQuery shown below) add a class when you hover over an element, a very simple example here: http://jsfiddle.net/btg5y/ p>
HTML:
<div id="list"> <p>Hover over me!</p> <ul> <li>item 1</li> <li>item 2</li> </ul> </div> <p>Click anywhere here to remove the hover</p>
JS:
$('#list').hover(function() { $('ul', this).addClass('pseudoHover'); }); $(document).click(function() { $('#list ul').removeClass('pseudoHover'); });
CSS
ul { background-color: #F00; height: 0; overflow: hidden; transition: height 1s; -webkit-transition: height 1s; } #list:hover ul, .pseudoHover { height: 50px; }
JavaScript is only used to add and remove a class as optional to preserve the state you require. If you do not have JavaScript, then only :hover
works.
Other than that, I donβt see how you do it with just CSS.
source share