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

  • SEARCH
  • Home
  • 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 743761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:54:03+00:00 2026-05-14T08:54:03+00:00

I’m trying to do a simple animation. You show the div. It animates correctly.

  • 0

I’m trying to do a simple animation.

  1. You show the div. It animates correctly.
  2. You hide the div. Correct.
  3. You show the div again. It shows but there is no animation. It is stuck at the value of when you first interrupted it.

So somehow the interpolation CSS that is happening during [add|remove]Class is getting stuck there. The second time around, the [add|remove]Class is actually running, but the css it’s setting from the class is getting ignored (I think being overshadowed). How can I fix this WITHOUT resorting to .animate and hard-coded style values? The whole point was to put the animation end point in a css class.

Thanks!

<!doctype html>

<style type="text/css">
div {
    width: 400px;
    height: 200px;
}
.green {
    background-color: green;
}
</style>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
    $('#show').bind({
        click: function() {
            showAndRun()
        }
    })
    $('#hide').bind({
        click: function() {
            $('div').stop(true, false).fadeOut('slow')
        }
    })

    function showAndRun() {
        function pulse() {
            $('div').removeClass('green', 2000, function() {
                $(this).addClass('green', 2000, pulse)
            })
        }
        $('div').stop(true, false).hide().addClass('green').fadeIn('slow', pulse)
    }
})
</script>

<input id="show" type="button" value="show" /><input id="hide" type="button" value="hide" />
<div style="display: none;"></div>

You can also look at what it does here at jsbin

  • 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-14T08:54:04+00:00Added an answer on May 14, 2026 at 8:54 am

    I figured out the solution. Not sure if I’m happy with it yet though. It’s essentially a very poor “reset” of the CSS when show is clicked

    The animation loops forever. So I can’t rely on a jQuery queue (finite length). I have to achieve the loop via the callback as shown in the code. The problem that causes: you can’t .stop(true, true) . The first true clears the queue, but there is nothing in the queue after the animation that is currently running. So that’s useless. The second true jumps to the last animation in the queue. Again useless, since we’re actually going to be staying in the one thing that is looping on itself. The 2nd arg must be false to interrupt the, otherwise, infinite loop.

    The problem with interruption. It leaves the css where it is. You are now stuck with random css props on whatever it was that your animation was interpolating over (in my case the background-color). Also I wanted the interruption to be instant. So there was no other way.

    In my case, the background-color during the animation was being set on element.style (discovered by inspection in browser tools), which overrides anything else that’s going on. This prop did not exist until the first animation had started running. Then it got interrupted and the supposed-to-be-temporary style got stuck there (I guess).

    So you run the animation again. The green class is applied. jQuery figures out the range of colors to progress through. Turns out its from #shadeofgreen to #thesameshadeofgreen, because the stuck element.styles value overrides anything provided by the class. So the animation slides between two of the same color. It’s running! But there’s no color to change to.

    So the fix in my case isn’t horrible, but I’m still not sure I like it, because I’m not sure it could be easily applied to a variety of situations.

    Change

    $('div').stop(true, false).hide().addClass('green').fadeIn('slow', pulse)
    

    to

    $('div').stop(true, false).removeAttr('style').hide().addClass('green').fadeIn('slow', pulse)
    

    The key is the

    .removeAttr('style').hide().addClass('green')
    

    That is essentially your css reset. Guaranteed to always be there when you need it since it’s happening exactly before the thing will get displayed again.

    Note that putting !important on the color in the green css class, doesn’t work, because that (seems to) will override element.styles (which the jQuery animation uses), and you will not get the desired result.

    Of course I am still open to suggestions. I probably missed something since I only started looking at CSS and jQuery at the top of the week.

    You can see the effects of the .removeAttr('style') in the fixed code here on jsbin.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
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.