This is a neat effect which
spins the social icons with the help of a CSS transform and transition when you
hover over them.
Let’s start with the structure
of the social media icons. Which is nothing more than a list with an extra span
to contain the icon itself because we want to include the full logo alongside
the icon.
01
|
<ul id="social" class="group">
|
CSS
Here’s the CSS focusing only on
the code that perform the transitions which is all we need for the purposes of
this tutorial.
01
|
li a span
{
|
02
|
-webkit-transition:
-webkit-transform 0.4s ease-out;
|
03
|
-moz-transition:
-moz-transform 0.4s ease-out;
|
04
|
transition:
transform 0.4s ease-out;
|
05
|
}
|
06
|
li
a:hover span {
|
07
|
-webkit-transform:
rotateZ(360deg);
|
08
|
-moz-transform:
rotateZ(360deg);
|
09
|
transform:
rotateZ(360deg);
|
10
|
}
|
We want the transition to
happen on the icon contained in the span
tag. we place it there as a global style
which will activate on any behavourial property such as:hover
or :active
. We
could associate it with the hover if we wanted to.
Let’s look at the transform
code first. This is ending position of where we want the icon to be and in this
case we actually want it to spin around in 360 degrees around the Z-axis which
is the axis that extends away from the screen.
Without the transition, nothing
appears to be happening. Rotating by 360 degrees obviously is going to cause
the icon to come ‘full circle’, visually back to the same position it started
from but the browser recognises it as a separate position. By adding the
transition property, we’re telling the browser to essentially animate between
two points. The default starting point for the rotation is 0 degrees and the
second point on hover is 360.
1
|
transition:
transform 0.4s ease-out;
|
The first part of the
transition is what property we want transitioned which of course is the
transform. You can also define all
or separate properties with commas. The 0.4s
is the
duration and ease-out
is the timing function.
Very simple to implement.
Currently works in WebKit browsers (Chrome and Safari) and Firefox 4. Have fun.
0 comments:
Post a Comment