Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7089287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:54:12+00:00 2026-05-28T07:54:12+00:00

I’ve got an array of words I want to iterate through on a page,

  • 0

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.

I’m using animate.css to handle the animations via adding and removing a class.

The initial div has an entrance class .rotateIn on it, and so animates on page render. It also has a .animated class on it, which must be present in order for the animation to be triggered.

After a two second delay, I add the exit animation class .rotateOut, then remove the entrance class, which then triggers the exit animation. At this point, the div is hidden.

I change the text, then add the entrance class, then remove the exit class, triggering the entrance animation.

Once I hit the last word in the array, the function stops.

What’s the best way to write this in coffeescript so that I can tweak the timings between entrance and exit?

EDIT: 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 ['foo', 'bar'] rather than the fragile PITA way below.

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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:54:13+00:00Added an answer on May 28, 2026 at 7:54 am

    Rather than setting a timeout each time, you should try using an interval that fires the same callback until you’ve reached the end. Take a look at this example, then add in your extra bits for animating.

    words = ["hey", "just", "testing", "this", "out"]
    i = 0
    len = words.length
    
    callback = ->
        clearInterval timer if i is len - 1
        console.log words[i]
        i++
        return
    
    timer = setInterval callback, 1000
    

    Just for clarity’s sake, here is the compiled JS

    (function() {
      var callback, i, len, timer, words;
      words = ["hey", "just", "testing", "this", "out"];
      i = 0;
      len = words.length;
    
      callback = function() {
        if (i === len - 1) clearInterval(timer);
        console.log(words[i]);
        i++;
      };
    
      timer = setInterval(callback, 1000);
    }).call(this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want use html5's new tag to play a wav file (currently only supported
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.