In other words, “Different transitions on mouseenter
and mouseleave
” as those are the DOM events that happen, but we’re not using JavaScript here, we’re talking about CSS :hover
state and CSS3 transitions. Hover on, some CSS property animates itself to a new value; hover off, a different CSS property animates.
This is a simple trick. You set transitions on both states, like this:
#thing {
padding: 10px;
border-radius: 5px;
/* HOVER OFF */
-webkit-transition: padding 2s;
}
#thing:hover {
padding: 20px;
border-radius: 15px;
/* HOVER ON */
-webkit-transition: border-radius 2s;
}
When you hover over, the :hover transition overrides the transition set in the regular state, and that property animates. When you hover off, the transition from the regular state takes over and that property animates.
And now, here an offensively lame examples that you should never use:
Interesting, has a wild spin in Chrome.
Indeed, it’s like the element get’s tangled within a smaller parrent. Really weird shit happening in Chrome. I bet you tried it in Safari, so it’s not a webkit quirk. Any thoughts on that, Chris?
If you look at the source it has the rotation transition in there. It’s not a bug ;)
Works fine in Chrome here. Ubuntu 10.10.
Yup, not a bug – just cheezy. As described!
Awesome, thank you!
Yep, dead cheezy but cool.
As people said – cheezy but cool :)
(trackback from Rinnku.com)
Thats such an obnoxious button lol. Cool idea though
That’s a nice trick, thanks for sharing!
So simple! Thanks for the write-up Chris, made the logic real easy to follow.
I really like your animated button – that will look really nice on my customer site. Could you kindly send teh codez to my e-mail address?
Right click and view source or inspect element – easiest way to grab the code! And in his examples Chris usually writes the CSS in the head instead of a linked file so it’s easier to grab the code.
I’d be so afraid to hover off and get that crazy spin animation that I would convert every time. Diabolical! ;) Very nice Chris!
lol
Its awesome but I think it has no use of it…
Then you’re not a very good thinker… Use a fade and it fades in and out – looks really nice. Slight growth and shrinking looks nice, box-shadow can be used to give a feeling of depth with the transitions, countless applications with very little coding effort.
Nice trick sir, I think i can experiment from this point onwards with this hover off thingy.
I’d say this is incredibly useful. There are of course lots of fun & entertaining uses for this, but Chris has also showcased what I’d say is a key part in transitioning hover states.
For example, you want a slow fade in color or opacity on a link (3s) or so— that could be so slow that users fail to even recognize the link when hovering. By specifying a shorter timing for the :hover state, you’ll be able to get a quick snap of the users attention on hover while retaining a smooth, slower fade out when the mouse leaves.
I wish there was a like button!
Great fancy button but one problem when i hover over the button, the scrollbar appears.
An interesting thing to remember when coming up with the ‘state’ transition is that it will activate on page load too…
A good thing to remember if you have a 10 second flashing whirly thing that is supposed to be a top secret ‘mouse off’ event.
My favorite part is how slow it runs. People keep pushing CSS3 over Flash for animation, but in the current state it’s too choppy to compete.
There are definitely concerns here. Especially with super simple little animations like that causing slowdowns. I wish there was some really good research on it.
Cool. But a real buy now button would be red…
? Please explain
Probably because red is more eye-catchy is what he was going for? I have noo idea..
the problem is how to give an animation on hover off using jQuery
Nice trick. I will play around with it for a while and see how to make it a bit smooth. Thanks.
hi
great web site ! thanx !!!
how about telling us where to get the menu as you have here. ? ;)
Inspired by your article I made this: http://userstyles.org/styles/43998
I used this for an experimental dropdown navigation.
For that navigation I’ve added a delayed transition of opacity and z-index on hover.
See http://dl.dropbox.com/u/1496903/css3menu_1.html for the source.
The relevant css:
Thanks for your simple but handy post! I tried it out and I’m very happy to learn how easy transitions are in CSS3. And I didn’t know I can put a :hover on any div, I thought only on ‘s.
Sir,
I added few more things to animate my div element …
three{
}
three:hover{
}
The animation works fine, with the exception that when you remove your cursor from the element it abruptly stops. Is there anyway to force it to continue even if the mouse has exited?
Also, it would be a great help if you could please tell me how can I trigger this animation on clicking the “#three” element ??
Brilliant! Thank you very much for showing this tip!