Created
November 17, 2012 17:02
-
-
Save remybach/4097686 to your computer and use it in GitHub Desktop.
A CodePen by Rémy Bach. 3D CSS icon/label spin effect - Just a really nice way of hiding a label behind an icon/image and then revealing the label on hover.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="container"> | |
| <p>Normal speed. Hover to see the final effect</p> | |
| <ul> | |
| <li> | |
| <span class="icon"></span> | |
| <span class="label">item 1</span> | |
| </li> | |
| <li> | |
| <span class="icon"></span> | |
| <span class="label">item 2</span> | |
| </li> | |
| <li> | |
| <span class="icon"></span> | |
| <span class="label">item 3</span> | |
| </li> | |
| <li> | |
| <span class="icon"></span> | |
| <span class="label">item 4</span> | |
| </li> | |
| <li> | |
| <span class="icon"></span> | |
| <span class="label">item 5</span> | |
| </li> | |
| </ul> | |
| <p>Sloooooowed down to demonstrate the effect:</p> | |
| <ul class="slow"> | |
| <li> | |
| <span class="icon"></span> | |
| <span class="label">item 1</span> | |
| </li> | |
| <li> | |
| <span class="icon"></span> | |
| <span class="label">item 2</span> | |
| </li> | |
| <li> | |
| <span class="icon"></span> | |
| <span class="label">item 3</span> | |
| </li> | |
| <li> | |
| <span class="icon"></span> | |
| <span class="label">item 4</span> | |
| </li> | |
| <li> | |
| <span class="icon"></span> | |
| <span class="label">item 5</span> | |
| </li> | |
| </ul> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*===== Presentational/layout stuff =====*/ | |
| li { | |
| position:relative; | |
| text-align:center; | |
| width:75px; | |
| /* Decrease this number to *increase* the 3D effect (and vice versa). */ | |
| perspective:250 !important; | |
| } | |
| .icon { | |
| background:url(http://lorempixel.com/50/50/nature/1); | |
| display:inline-block; | |
| height:50px; | |
| width:50px; | |
| } | |
| li:nth-of-type(2n+2) .icon { | |
| background:url(http://lorempixel.com/50/50/nature/2); | |
| } | |
| li:nth-of-type(2n+3) .icon { | |
| background:url(http://lorempixel.com/50/50/nature/3); | |
| } | |
| li:nth-of-type(2n+4) .icon { | |
| background:url(http://lorempixel.com/50/50/nature/4); | |
| } | |
| li:nth-of-type(2n+5) .icon { | |
| background:url(http://lorempixel.com/50/50/nature/5); | |
| } | |
| .label { | |
| left:20px; | |
| position:absolute; | |
| top:17px; | |
| } | |
| /*===== Animation (ie: the good stuff) =====*/ | |
| li:hover .icon, .label { | |
| transform:translateZ(-32px) rotateY(180deg); | |
| animation-duration:0.33s; | |
| animation-name:rotateOut; | |
| animation-timing-function:linear; | |
| animation-fill-mode:forwards; | |
| } | |
| .icon, li:hover .label { | |
| animation-duration:0.33s; | |
| animation-name:rotateIn; | |
| animation-timing-function:linear; | |
| animation-fill-mode:forwards; | |
| } | |
| .slow .icon, .slow .label, | |
| .slow li:hover .icon, .slow li:hover .label { | |
| animation-duration:2s; | |
| } | |
| @keyframes rotateIn { | |
| 0% { | |
| opacity:0; | |
| transform:translateZ(-100px) translateX(0) rotateY(180deg); | |
| } | |
| /* | |
| We need to reset it back to negative to avoid it flipping around like crazy | |
| Comment this line out to see what I mean. | |
| */ | |
| 1% { | |
| transform:translateZ(-100px) rotateY(-180deg); | |
| } | |
| 50% { | |
| opacity:0.5; | |
| z-index:1; | |
| transform:translateZ(-50px) translateX(-25px) rotateY(-90deg); | |
| } | |
| 100% { | |
| opacity:1; | |
| z-index:1; | |
| transform:translateZ(0) translateX(0) rotateY(0deg); | |
| } | |
| } | |
| @keyframes rotateOut { | |
| 0% { | |
| opacity:1; | |
| transform:translateZ(0) translateX(0) rotateY(0deg); | |
| } | |
| 50% { | |
| opacity:0.5; | |
| z-index:0; | |
| transform:translateZ(-50px) translateX(25px) rotateY(90deg); | |
| } | |
| 100% { | |
| opacity:0; | |
| z-index:0; | |
| transform:translateZ(-100px) translateX(0) rotateY(180deg); | |
| } | |
| } | |
| /*===== Boring stuff =====*/ | |
| body { | |
| background:url(http://subtlepatterns.subtlepatterns.netdna-cdn.com/patterns/creampaper.png); | |
| padding:20px; | |
| } | |
| .container { | |
| margin:0 auto; | |
| width:425px; | |
| } | |
| p { margin-bottom:10px; } | |
| ul { | |
| margin-bottom:20px; | |
| overflow:hidden; /* contain floats */ | |
| } | |
| li { | |
| float:left; | |
| margin-right:10px; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment