Note that there are some explanatory texts on larger screens.

plurals
  1. POPossible to reverse a css animation on class removal?
    primarykey
    data
    text
    <p>Essentially what I'm trying to do is give an element a CSS animation when it gains a class, then reverse that animation when I remove the class <strong>without playing the animation when the DOM renders</strong>.</p> <p>Fiddle here: <a href="http://jsfiddle.net/bmh5g/" rel="noreferrer">http://jsfiddle.net/bmh5g/</a></p> <p>As you can see in the fiddle, when you hover the "Hover Me" button, <code>#item</code> flips down. When you mouseoff the hover button, <code>#item</code> just disappears. I want <code>#item</code> to flip back up (ideally using the same animation but in reverse). Is this possible?</p> <p>HTML:</p> <pre class="lang-html prettyprint-override"><code>&lt;div id='trigger'&gt;Hover Me&lt;/div&gt; &lt;div id='item'&gt;&lt;/div&gt; </code></pre> <p>CSS:</p> <pre><code>#item { position: relative; height: 100px; width: 100px; background: red; -webkit-transform: perspective(350px) rotateX(-90deg); transform: perspective(350px) rotateX(-90deg); -webkit-transform-origin: 50% 0%; transform-origin: 50% 0%; } #item.flipped { animation: flipper 0.7s; animation-fill-mode: forwards; -webkit-animation: flipper 0.7s; -webkit-animation-fill-mode: forwards; } @keyframes flipper { 0% { transform: perspective(350px) rotateX(-90deg); } 33% { transform: perspective(350px) rotateX(0deg); } 66% { transform: perspective(350px) rotateX(10deg); } 100% { transform: perspective(350px) rotateX(0deg); } } @-webkit-keyframes flipper { 0% { -webkit-transform: perspective(350px) rotateX(-90deg); } 33% { -webkit-transform: perspective(350px) rotateX(0deg); } 66% { -webkit-transform: perspective(350px) rotateX(10deg); } 100% { -webkit-transform: perspective(350px) rotateX(0deg); } } </code></pre> <p>Javascript:</p> <pre><code>$('#trigger').on({ mouseenter: function(){ $('#item').addClass('flipped'); }, mouseleave: function(){ $('#item').removeClass('flipped'); } }) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload