Multiple CSS animations on an element

Groen91

I have this short piece of code which fades out my navigation bar. Everything is working fine.

The visible part:

.navigation-visible {
    position: fixed;
    top: 0;
    left: 0;
    background: blue;

   -webkit-opacity: 1;
   -moz-opacity: 1;
    opacity: 1;
}

The part when it's hidden:

.navigation-not-visible {
    position: fixed;
    top: 0;
    left: 0;
    background: blue;

   -webkit-opacity: 0;
   -moz-opacity: 0;
    opacity: 0;
   -webkit-transition: all 800ms ease;
   -moz-transition: all 800ms ease;
   -ms-transition: all 800ms ease;
   -o-transition: all 800ms ease;
   transition: all 800ms ease;
}

What I'd like to do now, is to add a another animation which directly moves my navigation bar -100px to the top after it has been faded out.

So I tried this code, but of course I failed miserably.

-webkit-transition: all 800ms ease, position translateY(-100%);

The big question: What am I doing wrong here?

Jonathan

Depending on your needed browser support, you could use CSS3 animations. This also requires a little JavaScript, but I'm assuming that you already are using JavaScript if you are changing the class name?

<div class="navigation-not-visible" id="navigation" style="display:none;">
  Navigation  ;)
</div>

<div id="quadraflunk"><br/>Smile and click me</div>

<style type="text/css">

  .navigation-visible {
    position: fixed;
    top: 0;
    left: 0;
    background: blue;

    opacity: 1;
  }

  .navigation-not-visible {
    position: fixed;
    top: -100%;
    left: 0;
    background: blue;

    opacity: 0.2;
   -webkit-transition: all 800ms ease;
   -moz-transition: all 800ms ease;
   -ms-transition: all 800ms ease;
   -o-transition: all 800ms ease;
   transition: all 800ms ease;
    animation-name: example;
    animation-duration: 800ms;
    -webkit-animation-name: example; /* Chrome, Safari, Opera */
    -webkit-animation-duration: 800ms; /* Chrome, Safari, Opera */
  }

  @keyframes example {
    0%   {opacity: 1;top:0;}
    99%  {opacity: 0;top:0;}
    100% {top: -100%;}
  }
  @-webkit-keyframes example {
    0%   {opacity: 1;top:0;}
    99%  {opacity: 0;top:0;}
    100% {top: -100%;}
  }
</style>

<script type="text/javascript">
  document.getElementById("quadraflunk").onclick = function() {
    if (document.getElementById("navigation").className == "navigation-visible") {
      document.getElementById("navigation").className = "navigation-not-visible";
    }
    else {
      document.getElementById("navigation").style.display = "";
      document.getElementById("navigation").className = "navigation-visible";
    }
  }
</script>

Here's a little fiddle to demonstrate: https://jsfiddle.net/bruwpaaz/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Multiple CSS animations on an element

From Dev

Multiple animations for 1 element JS, CSS

From Dev

Multiple animations on SVG element

From Dev

Chaining Multiple CSS Animations

From Dev

Trigger CSS animations by hovering over a seperate element

From Java

Play multiple CSS animations at the same time

From Dev

Multiple animations with CSS3 not working as expected

From Dev

CSS Selectors - Multiple animations on one trigger

From Dev

CSS loads animations on multiple lines at the same time

From Dev

Javascript button to toggle multiple css animations

From Dev

Using CSS animations on element containing a focused input box

From Dev

FadeOut element to FadeIn another in the same place with CSS animations

From Dev

Why are my CSS animations triggered by hovering over the wrong element?

From Dev

Trying to make different hover animations for multiple images in css

From Dev

CSS Animations vs JQuery Animations

From Dev

Multiple :selectors on one CSS element?

From Dev

How to add multiple CSS styles to an element with .css()

From Dev

Multiple animations(threads) in a JPanel

From Dev

Control multiple canvas animations

From Dev

Combine multiple animations

From Dev

Jitter on chrome css animations

From Dev

css animations created by javascript

From Dev

Jitter on chrome css animations

From Dev

Disable CSS animations on Firefox

From Dev

CSS animations transform qustion

From Dev

CSS Animations : -Webkits in webkits

From Dev

optimize css animations with javascript

From Dev

Sequential animations in javascript/css

From Dev

Simplify animations in css