<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>140853</bug_id>
          
          <creation_ts>2015-01-24 00:31:32 -0800</creation_ts>
          <short_desc>Animations not showing upon adding/removal of classes</short_desc>
          <delta_ts>2023-05-10 01:14:05 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Animations</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>lentiformnucleus</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>dino</cc>
    
    <cc>graouts</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1063896</commentid>
    <comment_count>0</comment_count>
    <who name="">lentiformnucleus</who>
    <bug_when>2015-01-24 00:31:32 -0800</bug_when>
    <thetext>Animations fail to &quot;execute&quot; when they are called the SECOND time around by the method of adding and removing classes that reference that animation in a CSS stylesheet(or inline CSS), with JavaScript&apos;s classList.add() and classList.remove() methods.

CSS RULES START

@-webkit-keyframes fadeIn {
  to {
    opacity: 1;
  }
}
@keyframes fadeIn {
  to {
    opacity: 1;
  }
}

.fadeIn {
  -webkit-animation: fadeIn .5s ease-in 1 forwards;
  animation: fadeIn .5s ease-in 1 forwards;
}

CSS RULES END

JAVASCRIPT CODE START

element = document.getElementById(&quot;anyElement&quot;);

var effect = {

    fadeIn: function(el) {

        el.style.opacity = 0;
        el.classList.remove(&quot;fadeIn&quot;);
        el.classList.add(&quot;fadeIn&quot;);

    }

};

effects.fadeIn(element);

JAVASCRIPT CODE END

By coding it this way, it works only under Firefox. However, there&apos;s a workaround in Webkit browsers, and that is by adding a timeout to the class addition, like so:

    fadeIn: function(el) {

        el.style.opacity = 0;
        el.classList.remove(&quot;fadeIn&quot;);
        setTimeout(el.classList.add(&quot;fadeIn&quot;), 25);

    }

This way, the animation starts as it should, but a timeout shouldn&apos;t be required for it to work. I&apos;m thinking, therefore, that it is a bug. (Note that the timeout of 25 is more or less arbitrary, but a number too small won&apos;t fix the behaviour)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1063897</commentid>
    <comment_count>1</comment_count>
    <who name="">lentiformnucleus</who>
    <bug_when>2015-01-24 00:36:51 -0800</bug_when>
    <thetext>Sorry, there&apos;s a small typo in the code. var effect should be var effects. And also, the &apos;fadeIn&apos; method should be called more than once for the bug to be noticeable (note that in the code, I only call it once). Please make the pertintent amendments.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1063898</commentid>
    <comment_count>2</comment_count>
    <who name="">lentiformnucleus</who>
    <bug_when>2015-01-24 00:42:32 -0800</bug_when>
    <thetext>
(In reply to comment #1)
&gt; Sorry, there&apos;s a small typo in the code. var effect should be var effects.
&gt; And also, the &apos;fadeIn&apos; method should be called more than once for the bug to
&gt; be noticeable (note that in the code, I only call it once). Please make the
&gt; pertintent amendments.

Aaaah, setTimeout(el.classList.add(&quot;fadeIn&quot;), 25); should read instead:

setTimeout(function(){ el.classList.add(&quot;fadeIn&quot;); }, 25);

As you of course know. Sorry, I&apos;m getting sleepy.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1954272</commentid>
    <comment_count>3</comment_count>
      <attachid>466305</attachid>
    <who name="Antoine Quint">graouts</who>
    <bug_when>2023-05-10 01:12:58 -0700</bug_when>
    <thetext>Created attachment 466305
Test

It would help to have a test case to run, but I believe I&apos;ve recreated one that shows what was described by the originator.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1954273</commentid>
    <comment_count>4</comment_count>
    <who name="Antoine Quint">graouts</who>
    <bug_when>2023-05-10 01:14:05 -0700</bug_when>
    <thetext>I&apos;m going to close this, removing the &quot;fadeIn&quot; class and adding straight away without waiting for style resolution should indeed NOT trigger a new animation. The test case I wrote behaves the same between Firefox and Safari. If you find this is not correct, please reopen this bug with a test case showing the issue.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>466305</attachid>
            <date>2023-05-10 01:12:58 -0700</date>
            <delta_ts>2023-05-10 01:12:58 -0700</delta_ts>
            <desc>Test</desc>
            <filename>bug-140853.html</filename>
            <type>text/html</type>
            <size>759</size>
            <attacher name="Antoine Quint">graouts</attacher>
            
              <data encoding="base64">PHN0eWxlPgogICAgQC13ZWJraXQta2V5ZnJhbWVzIGZhZGVJbiB7CiAgICAgIHRvIHsKICAgICAg
ICBvcGFjaXR5OiAxOwogICAgICB9CiAgICB9CiAgICBAa2V5ZnJhbWVzIGZhZGVJbiB7CiAgICAg
IHRvIHsKICAgICAgICBvcGFjaXR5OiAxOwogICAgICB9CiAgICB9CgogICAgLmZhZGVJbiB7CiAg
ICAgIC13ZWJraXQtYW5pbWF0aW9uOiBmYWRlSW4gLjVzIGVhc2UtaW4gMSBmb3J3YXJkczsKICAg
ICAgYW5pbWF0aW9uOiBmYWRlSW4gLjVzIGVhc2UtaW4gMSBmb3J3YXJkczsKICAgIH0gICAKCiAg
ICBkaXYgewogICAgICAgIHdpZHRoOiAxMDBweDsKICAgICAgICBoZWlnaHQ6IDEwMHB4OwogICAg
ICAgIGJhY2tncm91bmQtY29sb3I6IGJsYWNrOwogICAgICAgIG9wYWNpdHk6IDA7CiAgICB9Cjwv
c3R5bGU+Cgo8ZGl2PjwvZGl2PgoKPHNjcmlwdD4KICAgIGVsZW1lbnQgPSBkb2N1bWVudC5xdWVy
eVNlbGVjdG9yKCJkaXYiKTsKCiAgICB2YXIgZWZmZWN0ID0gewoKICAgICAgICBmYWRlSW46IGZ1
bmN0aW9uKGVsKSB7CgogICAgICAgICAgICBlbC5zdHlsZS5vcGFjaXR5ID0gMDsKICAgICAgICAg
ICAgZWwuY2xhc3NMaXN0LnJlbW92ZSgiZmFkZUluIik7CiAgICAgICAgICAgIGVsLmNsYXNzTGlz
dC5hZGQoImZhZGVJbiIpOwoKICAgICAgICB9CgogICAgfTsKCiAgICBlZmZlY3QuZmFkZUluKGVs
ZW1lbnQpOwoKICAgIHNldFRpbWVvdXQoKCkgPT4geyBlZmZlY3QuZmFkZUluKGVsZW1lbnQpIH0s
IDIwMDApOwo8L3NjcmlwdD4K
</data>

          </attachment>
      

    </bug>

</bugzilla>