Note that there are some explanatory texts on larger screens.

plurals
  1. POCoffeescript to iterate through an array of words on a page?
    primarykey
    data
    text
    <p>I've got an array of words I want to iterate through on a page, making the existing word rotate out, and a new word rotate in.</p> <p>I'm using <a href="http://daneden.me/animate/" rel="nofollow">animate.css</a> to handle the animations via adding and removing a class.</p> <p>The initial div has an entrance class <code>.rotateIn</code> on it, and so animates on page render. It also has a <code>.animated</code> class on it, which must be present in order for the animation to be triggered.</p> <p>After a two second delay, I add the exit animation class <code>.rotateOut</code>, then remove the entrance class, which then triggers the exit animation. At this point, the div is hidden.</p> <p>I change the text, then add the entrance class, then remove the exit class, triggering the entrance animation.</p> <p>Once I hit the last word in the array, the function stops.</p> <p>What's the best way to write this in coffeescript so that I can tweak the timings between entrance and exit?</p> <p><strong>EDIT:</strong> here's some basic javascript code showing what I'm trying to do. I'd like to rewrite this so that I can set an array of words <code>['foo', 'bar']</code> rather than the fragile PITA way below.</p> <pre><code>var $adj = $('#adjectives'); setTimeout(function() { $adj.addClass('rotateOut'); setTimeout(function() { $adj.removeClass('rotateIn'); setTimeout(function() { $adj.text('foo'); $adj.addClass('rotateIn'); setTimeout(function() { $adj.removeClass('rotateOut'); setTimeout(function() { $adj.addClass('rotateOut'); setTimeout(function() { $adj.removeClass('rotateIn'); setTimeout(function() { $adj.text('bar'); $adj.addClass('rotateIn'); }, 1000); }, 1000); }, 1000); }, 1000); }, 1000); }, 1000); }, 1000); </code></pre>
    singulars
    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.
 

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