I am trying to create a logo transition with css however it only works in Chrome and not FF or even IE so what should i do ?
MY CSS
.logo {
-moz-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
-webkit-transition: all 0.5s ease;
transition: all 0.5s ease;
background-image: url(../images/text.enter.png);
border-style: none;
height: 70px;
left: 50%;
margin-left: -138.5px;
margin-top: -35px;
position: absolute;
top: 50%;
width: 277px;
}
.logo:hover { background-image: url(../images/logo.png); }
Demo : http://jsfiddle.net/lotusgodkk/GCu2D/242/
CSS:
* {
margin: 0;
padding: 0;
}
#nav li:hover {
-webkit-animation: NAME-YOUR-ANIMATION 500ms;
/* Safari 4+ */
-moz-animation: NAME-YOUR-ANIMATION 500ms;
/* Fx 5+ */
-o-animation: NAME-YOUR-ANIMATION 500ms;
/* Opera 12+ */
animation: NAME-YOUR-ANIMATION 500ms;
/* IE 10+, Fx 29+ */
}
#nav {
width: 400px;
margin: 40px auto;
}
#nav li {
list-style-type:none;
font-size:2em;
}
#nav li a {
background-image:url('http://css-tricks.com/examples/CSS-Sprites/Example1After/img/image_nav.gif');
background-repeat:no-repeat;
padding: 0 0 0 90px;
display: block;
height: 72px;
}
#nav li a.item1 {
background-position:0px 0px;
}
#nav li a:hover.item1 {
background-position:0px -72px;
}
#nav li a.item2 {
background-position:0px -143px;
}
#nav li a:hover.item2 {
background-position:0px -215px;
}
#nav li a.item3 {
background-position:0px -287px;
}
#nav li a:hover.item3 {
background-position:0px -359px;
}
#nav li a.item4 {
background-position:0px -431px;
}
#nav li a:hover.item4 {
background-position:0px -503px;
}
#nav li a.item5 {
background-position:0px -575px;
}
#nav li a:hover.item5 {
background-position:0px -647px;
}
#-webkit-keyframes NAME-YOUR-ANIMATION {
0% {
opacity: 1;
}
50% {
opacity:0.5;
}
100% {
opacity: 1;
}
}
#-moz-keyframes NAME-YOUR-ANIMATION {
0% {
opacity: 1;
}
50% {
opacity:0.5;
}
100% {
opacity: 1;
}
}
#-o-keyframes NAME-YOUR-ANIMATION {
0% {
opacity: 1;
}
50% {
opacity:0.5;
}
100% {
opacity: 1;
}
}
#keyframes NAME-YOUR-ANIMATION {
0% {
opacity: 1;
}
50% {
opacity:0.5;
}
100% {
opacity: 1;
}
}
HTML:
<ul id="nav">
<li><a class="item1" href="#" title="Some Link 1">Item 1</a>
</li>
<li><a class="item2" href="#" title="Some Link 2">Item 2</a>
</li>
<li><a class="item3" href="#" title="Some Link 3">Item 3</a>
</li>
<li><a class="item4" href="#" title="Some Link 4">Item 4</a>
</li>
<li><a class="item5" href="#" title="Some Link 5">Item 5</a>
</li>
</ul>
I used keyframes for animation. You can learn more about it here: http://css-tricks.com/snippets/css/keyframe-animation-syntax/
The example may not be perfect as per your needs but it can surely help you to achieve what you want.
Related
I'm using keyframes so fade in the items on click, but I want them to then fade out when I click again. How do I do this with keyframes? Maybe this is something you can't actually do with keyframes?
codepen
<div class="icon-wrap" onclick="bunAnimate(this)">
click me
</div>
<div class="primary__nav">
<ul id="primary" class="menu">
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
.primary__nav {
display: none;
&.open {
display: block;
}
}
.icon-wrap {
cursor: pointer;
}
ul {
position: relative;
list-style-type: none;
display: flex;
margin-bottom: 0;
li {
opacity: 0;
-webkit-animation: fadeInRight 0.5s linear forwards;
animation: fadeInRight 0.5s linear forwards;
-webkit-animation-delay: 0.35s;
animation-delay: 0.35s;
}
li:nth-of-type(2) {
-webkit-animation-delay: 0.4s;
animation-delay: 0.4s;
}
li:nth-of-type(3) {
-webkit-animation-delay: 0.45s;
animation-delay: 0.45s;
}
li:nth-of-type(4) {
-webkit-animation-delay: 0.5s;
animation-delay: 0.5s;
}
li:nth-of-type(5) {
-webkit-animation-delay: 0.55s;
animation-delay: 0.55s;
}
}
#-webkit-keyframes fadeInRight {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes fadeInRight {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
function bunAnimate(x) {
$(".icon-wrap").toggleClass("open");
$(".primary__nav").toggleClass("open");
}
You can make the list fade out item by item on click by more-or-less reversing the process.
There is one slight problem though, it's not possible to do this entirely in CSS as animations will not set the display property, so we can't get a keyframes declaration to set display: none on the primary nav element when the fading out has all completed. We get round this by introducing another class, display, which we call through Javascript. This is done rather crudely with a setTimeout, it may be possible to be more sophisticated by listening for the end of an animation, but it basically comes to the same thing.
function bunAnimate(x) {
document.querySelector(".icon-wrap").classList.toggle("open");
if (!document.querySelector(".primary__nav").matches('.open')) {
document.querySelector(".primary__nav").classList.add("open");
document.querySelector(".primary__nav").classList.add('display'); //display immediately it's open
}
else {
document.querySelector(".primary__nav").classList.remove("open");
setTimeout(function () {
document.querySelector(".primary__nav").classList.remove("display");
},550);//unpleasant but animations don't allow setting of display
}
}
.primary__nav {
display: none;
}
.primary__nav.display{
display: block;
}
.icon-wrap {
cursor: pointer;
}
ul {
position: relative;
list-style-type: none;
display: flex;
margin-bottom: 0;
}
li {
animation-name: fadeOutLeft;
animation-timing-function: linear;
animation-fill-mode: forwards;
}
li:nth-of-type(1) {
animation-delay: 0.55s;
}
li:nth-of-type(2) {
animation-delay: 0.5s;
}
li:nth-of-type(3) {
animation-delay: 0.45s;
}
li:nth-of-type(4) {
animation-delay: 0.4s;
}
li:nth-of-type(5) {
animation-delay: 0.35s;
}
.open li {
display: block;
opacity: 0;
animation-name: fadeInRight;
}
.open li:nth-of-type(1) {
animation-delay: 0.35s;
}
.open li:nth-of-type(2) {
animation-delay: 0.4s;
}
.open li:nth-of-type(3) {
animation-delay: 0.45s;
}
.open li:nth-of-type(4) {
animation-delay: 0.5s;
}
.open li:nth-of-type(5) {
animation-delay: 0.55s;
}
#keyframes fadeInRight {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes fadeOutLeft {
0% {
}
100% {
opacity: 0;
}
}
<div class="icon-wrap" onclick="bunAnimate(this)">
click me
</div>
<div class="primary__nav">
<ul id="primary" class="menu">
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
Note: I used pure CSS as I'm not familiar with SCSS.
I have a menu in an ul-list in a div-container:
<div class="box">
<div class="fullwidth-menu-nav">
<ul>
<li>Menu 1</li>
<li>Menu 2</li>
<li>Menu 3</li>
<li>Menu 4</li>
</ul>
</div>
</div>
Here is the CSS-stylesheet:
#-webkit-keyframes fadeIn { from { opacity:1; } to { opacity:0; } }
#-moz-keyframes fadeIn { from { opacity:1; } to { opacity:0; } }
#keyframes fadeIn { from { opacity:1; } to { opacity:0; } }
.fullwidth-menu-nav {
position:absolute;
width: 100%;
opacity:1;
-webkit-animation:fadeIn ease-in 1; /* call our keyframe named fadeIn, use animattion ease-in and repeat it only 1 time */
-moz-animation:fadeIn ease-in 1;
animation:fadeIn ease-in 1;
-webkit-animation-fill-mode:forwards;
-moz-animation-fill-mode:forwards;
animation-fill-mode:forwards;
-webkit-animation-duration:1s;
-moz-animation-duration:1s;
animation-duration:1s;
}
.fullwidth-menu-nav ul li {
-webkit-animation-delay: 1.7s;
-moz-animation-delay: 1.7s;
animation-delay: 1.7s;
}
/*---make a basic box ---*/
.box{
width: 200px;
height: 200px;
position: relative;
margin: 10px;
float: left;
border: 1px solid #333;
background: #999;
}
html body div.box:hover {
opacity: 1;
visibility: visible;
border:8px solid #ff0;
}
When loading this side, the List-Menu is shown and disappers after a few millisecons. What I want to getist that if I hover over the Box-Div, the List-Menu is shown again.
So what is to do, to show the (invisible) li-Menu by hovering over another visible element (the Box-DIV)?
Yes, you could add another animation on hover to reverse the opacity you did:
.fullwidth-menu-nav:hover {
animation: appear 1s ease forwards;
}
#keyframes appear {
from { opacity:0; } to { opacity:1; }
}
I need to add an animation to this links on hover, I have to deal with the "width" of the link word can change. Is there any way to change dynamically the value of the translate animation?
.link {
text-decoration: none;
padding-left: 15px;
position: relative;
transition: 1s;
&:hover {
padding-left: 0;
.link--decoration {
animation: in 1s ease both;
}
}
}
.link--decoration {
animation: out 1s ease both;
left: 0;
position: absolute;
}
#keyframes in {
to {
transform: translate(calc(100% + 75px), 0);
}
}
#keyframes out {
from {
transform: translate(calc(100% + 75px), 0);
}
to {
transform: translate(0, 0);
}
}
<p><span class="link--decoration">‐</span><span class="link--text">Read Article</span></p>
<p><span class="link--decoration">‐</span><span class="link--text">Open Hours</span></p>
<p><span class="link--decoration">‐</span><span class="link--text">Open Localization</span></p>
https://codepen.io/serrazina/pen/zzEaLE
There are 2 approaches I see to solving this. The first uses left to animate the decoration. Like this:
.link {
text-decoration: none;
padding-left: 15px;
position: relative;
transition: 1s;
}
.link:hover {
padding-left: 0;
}
.link:hover .link--decoration {
animation: in 1s ease both;
}
.link--decoration {
animation: out 1s ease both;
left: 0;
position: absolute;
}
#keyframes in {
to {
left: calc(100% + 5px);
}
}
#keyframes out {
from {
left: calc(100% + 5px);
}
to {
left: 0;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p><span class="link--decoration">‐</span><span class="link--text">Read Article</span></p>
<p><span class="link--decoration">‐</span><span class="link--text">Open Hours</span></p>
<p><span class="link--decoration">‐</span><span class="link--text">Open Localization</span></p>
The second method uses transform to take advantage of hardware acceleration. The difference between this method and yours was adding a width: 100% to the decoration as the translate is based on the width of the element. In your example that meant transform: translateX(100%) was 100% the width of the decoration element, which was about 20px in width. In the demo below I've made the element 100% the width of it's parent element, so transform: translateX(100%) moves it to the right of the parent element.
.link {
text-decoration: none;
padding-left: 15px;
position: relative;
transition: 1s;
}
.link:hover {
padding-left: 0;
}
.link:hover .link--decoration {
animation: in 1s ease both;
}
.link--decoration {
animation: out 1s ease both;
left: 0;
width: 100%;
position: absolute;
}
#keyframes in {
to {
transform: translateX(calc(100% + 5px));
}
}
#keyframes out {
from {
transform: translateX(calc(100% + 5px));
}
to {
transform: translateX(0);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p><span class="link--decoration">‐</span><span class="link--text">Read Article</span></p>
<p><span class="link--decoration">‐</span><span class="link--text">Open Hours</span></p>
<p><span class="link--decoration">‐</span><span class="link--text">Open Localization</span></p>
I'm trying to learn how to animate with CSS in a DevTips Tutorial but had to stop about 8-minutes in since my code isn't animating the menu items properly. They simply pop into place, but are supposed to flip and fade in simultaneously.
I hope it isn't taboo to post something that's been written at CodePen; my sincerest apologies if it is. If it's kosher, CLICK HERE.
As far as I can tell, my code matches exactly what's in the tutorial, so I was hoping someone could spot whatever error I'm overlooking.
Achtung!! My codepen syntax is using Pug and SASS preprocessors, so if you don't like looking at that kind of syntax, the compiled HTML and CSS is included below.
Many thanks in advance.
HTML ::
<nav>
<ul>
<li>style 1
<ul class="drop-menu menu-#{i}">
<li>uno</li>
<li>dos</li>
<li>tres</li>
<li>cuatro</li>
<li>cinco</li>
<li>seis</li>
</ul>
</li>
<li>style 2
<ul class="drop-menu menu-#{i}">
<li>uno</li>
<li>dos</li>
<li>tres</li>
<li>cuatro</li>
<li>cinco</li>
<li>seis</li>
</ul>
</li>
<li>style 3
<ul class="drop-menu menu-#{i}">
<li>uno</li>
<li>dos</li>
<li>tres</li>
<li>cuatro</li>
<li>cinco</li>
<li>seis</li>
</ul>
</li>
<li>style 4
<ul class="drop-menu menu-#{i}">
<li>uno</li>
<li>dos</li>
<li>tres</li>
<li>cuatro</li>
<li>cinco</li>
<li>seis</li>
</ul>
</li>
</ul>
</nav>
CSS ::
nav {
padding: 50px;
text-align: center;
}
nav > ul {
list-style: none;
padding: 0;
margin: 0;
display: inline-block;
background: #ddd;
border-radius: 5px;
}
nav > ul > li {
float: left;
width: 150px;
height: 65px;
line-height: 65px;
position: relative;
text-transform: uppercase;
font-size: 14px;
color: DarkGray;
color: rgba(0, 0, 0, 0.7);
cursor: pointer;
}
nav > ul > li:hover {
background: #d5d5d5;
border-radius: 5px;
}
ul.drop-menu {
position: absolute;
top: 100%;
left: 0;
width: 100%;
padding: 0;
}
ul.drop-menu li {
background: #666;
color: White;
color: rgba(255, 255, 255, 0.7);
}
ul.drop-menu li:hover {
background: #606060;
}
ul.drop-menu li:last-child {
border-radius: 0 0 5px 5px;
}
ul.drop-menu li {
display: none;
}
li:hover > ul.drop-menu li {
display: block;
}
li:hover > ul.drop-menu.menu-1 {
-webkit-perspective: 1000px;
perspective: 1000px;
}
li:hover > ul.drop-menu.menu-1 li {
opacity: 0;
-webkit-animation-name: menu1;
animation-name: menu1;
-webkit-animation-duration: 500ms;
animation-duration: 500ms;
-webkit-animation-timing-function: ease-in-out;
animation-timing-function: ease-in-out;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
#-webkit-keyframes menu1 {
0% {
opacity: 0;
-webkit-transform: rotateY(-90deg) translateY(30px);
transform: rotateY(-90deg) translateY(30px);
}
100% {
opacity: 1;
-webkit-transform: rotateY(0deg) translateY(0px);
transform: rotateY(0deg) translateY(0px);
}
}
#keyframes menu1 {
0% {
opacity: 0;
-webkit-transform: rotateY(-90deg) translateY(30px);
transform: rotateY(-90deg) translateY(30px);
}
100% {
opacity: 1;
-webkit-transform: rotateY(0deg) translateY(0px);
transform: rotateY(0deg) translateY(0px);
}
}
Looks like you have a very simple problem with your Pug processing in this line:
ul(class="drop-menu menu-#{i}")
This isn't adding the class "menu-1" through "menu-4" as expected. To fix this write the Pug statement like this instead:
ul(class="drop-menu menu-" + i)
This is the new syntax that Pug specifies using, you can read more here.
I want to make the animation .logo to spin 360 degree ,its an image...any help please?
.logo {
top:35%;
left:70%;
position: absolute;
-webkit-animation-name: spin;
-webkit-animation-duration: 5000;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: ease-in;
}
#-webkit-keyframes spin {
0%{ -webkit-transform: rotate(0deg);}
100%{ -webkit-transform: rotate(360deg);}
}
nav ul {
-webkit-font-smoothing:antialiased;
text-shadow:0 1px 0 black;
background: #bcab98;
list-style: none;
margin: 0;
padding: 0;
width: 100%;
}
nav li {
float: left;
margin: 0;
padding: 0;
position: relative;
min-width: 25%;
}
nav a {
background: #ddd;
color: #444;
display: block;
font: bold 16px/50px sans-serif;
padding: 0 25px;
text-align: center;
text-decoration: none;
-webkit-transition: all .25s ease-in;
-moz-transition: all .25s ease-in;
-ms-transition: all .25s ease-in;
-o-transition: all .25s ease-in;
transition: all .25s ease-in;
}
nav a:hover{
text-decoration: underline;
}
nav li:hover{
text-decoration: none;
}
nav .dropdown1:after {
content: ' ▶';
}
nav .dropdown1:hover:after{
content:'\25bc';
}
nav .dropdown2:after {
content: ' ▶';
}
nav .dropdown2:hover:after{
content:'\25bc';
}
nav li:hover a {
background: #ccc;
}
nav li ul {
float: left;
left: 0;
opacity: 0;
position: absolute;
top: 35px;
visibility: hidden;
z-index: 1;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
nav li:hover ul {
opacity: 1;
top: 50px;
visibility: visible;
}
nav li ul li {
float: none;
width: 100%;
}
nav li ul a:hover {
background: #bbb;
}
.drop_down_menu_for_cafe:after, .cf:before {
content:"";
display:table;
}
.cf:after {
clear:both;
}
.cf {
zoom:1;
}
<nav>
<ul class="drop_down_menu_for_cafe">
<li><a class="dropdown1" href="#"> Coffee Menu </a>
<ul>
<li> Cappuccino coffee </li>
<li> Expresso coffee </li>
<li> Black coffee </li>
</ul>
</li>
<li><a class="dropdown2" href="#"> Tea </a>
<ul>
<li> Green tea </li>
<li> Black tea </li>
<li> Dark tea </li>
</ul>
</li>
<li><a class="about" href="#"> About </a></li>
<li><a class="contacts" href="#"> Contacts </a></li>
</ul>
</nav>
<img src="lattee.jpg" alt="latte_coffee" width="1180px" height="550px">
<span class="logo"><img class="logo" name="logo" src="coffee-logo.jpg" alt="latte_logo" width="200px" height="200px"></span>
The problem is that you have -webkit-animation-duration: 5000; instead of -webkit-animation-duration: 5000ms;:
... and you might also want to support other browsers
.logo {
top: 35%;
left: 70%;
position: absolute;
-webkit-animation-name: spin;
-webkit-animation-duration: 5000ms;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: ease-in;
-moz-animation-name: spin;
-moz-animation-duration: 5000ms;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: ease-in;
-ms-animation-name: spin;
-ms-animation-duration: 5000ms;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: ease-in;
}
#-moz-keyframes spin {
from {
-moz-transform: rotate(0deg);
}
to {
-moz-transform: rotate(360deg);
}
}
#-webkit-keyframes spin {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
#keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
nav ul {
-webkit-font-smoothing: antialiased;
text-shadow: 0 1px 0 black;
background: #bcab98;
list-style: none;
margin: 0;
padding: 0;
width: 100%;
}
nav li {
float: left;
margin: 0;
padding: 0;
position: relative;
min-width: 25%;
}
nav a {
background: #ddd;
color: #444;
display: block;
font: bold 16px/50px sans-serif;
padding: 0 25px;
text-align: center;
text-decoration: none;
-webkit-transition: all .25s ease-in;
-moz-transition: all .25s ease-in;
-ms-transition: all .25s ease-in;
-o-transition: all .25s ease-in;
transition: all .25s ease-in;
}
nav a:hover {
text-decoration: underline;
}
nav li:hover {
text-decoration: none;
}
nav .dropdown1:after {
content: ' ▶';
}
nav .dropdown1:hover:after {
content: '\25bc';
}
nav .dropdown2:after {
content: ' ▶';
}
nav .dropdown2:hover:after {
content: '\25bc';
}
nav li:hover a {
background: #ccc;
}
nav li ul {
float: left;
left: 0;
opacity: 0;
position: absolute;
top: 35px;
visibility: hidden;
z-index: 1;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
nav li:hover ul {
opacity: 1;
top: 50px;
visibility: visible;
}
nav li ul li {
float: none;
width: 100%;
}
nav li ul a:hover {
background: #bbb;
}
.drop_down_menu_for_cafe:after,
.cf:before {
content: "";
display: table;
}
.cf:after {
clear: both;
}
.cf {
zoom: 1;
}
<nav>
<ul class="drop_down_menu_for_cafe">
<li><a class="dropdown1" href="#"> Coffee Menu </a>
<ul>
<li> Cappuccino coffee
</li>
<li> Expresso coffee
</li>
<li> Black coffee
</li>
</ul>
</li>
<li><a class="dropdown2" href="#"> Tea </a>
<ul>
<li> Green tea
</li>
<li> Black tea
</li>
<li> Dark tea
</li>
</ul>
</li>
<li><a class="about" href="#"> About </a>
</li>
<li><a class="contacts" href="#"> Contacts </a>
</li>
</ul>
</nav>
<img src="lattee.jpg" alt="latte_coffee" width="1180px" height="550px">
<span class="logo"><img class="logo" name="logo" src="coffee-logo.jpg" alt="latte_logo" width="200px" height="200px"></span>
Use this way. You are not putting all the vendor prefixes and the duration should have units: 5000ms or 5s:
.element-animation {
animation: animationFrames linear 4s;
animation-iteration-count: infinite;
transform-origin: 50% 50%;
-webkit-animation: animationFrames linear 4s;
-webkit-animation-iteration-count: infinite;
-webkit-transform-origin: 50% 50%;
-moz-animation: animationFrames linear 4s;
-moz-animation-iteration-count: infinite;
-moz-transform-origin: 50% 50%;
-o-animation: animationFrames linear 4s;
-o-animation-iteration-count: infinite;
-o-transform-origin: 50% 50%;
-ms-animation: animationFrames linear 4s;
-ms-animation-iteration-count: infinite;
-ms-transform-origin: 50% 50%;
width: 50px; line-height: 50px; background: #99f; text-align: center;
}
#keyframes animationFrames {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
#-moz-keyframes animationFrames {
0% {
-moz-transform: rotate(0deg);
}
100% {
-moz-transform: rotate(360deg);
}
}
#-webkit-keyframes animationFrames {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
#-o-keyframes animationFrames {
0% {
-o-transform: rotate(0deg);
}
100% {
-o-transform: rotate(360deg);
}
}
#-ms-keyframes animationFrames {
0% {
-ms-transform: rotate(0deg);
}
100% {
-ms-transform: rotate(360deg);
}
}
<div class="element-animation">Logo</div>