Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To make <code>transition</code> work, three things have to happen. </p> <ol> <li>the element has to have the property explicitly defined, in this case: <code>opacity: 0;</code></li> <li>the element must have the transition defined: <code>transition: opacity 2s;</code></li> <li>the new property must be set: <code>opacity: 1</code></li> </ol> <p>If you are assigning 1 and 2 dynamically, like you are in your example, there needs to be a delay before 3 so the browser can process the request. The reason it works when you are debugging it is that you are creating this delay by stepping through it, giving the browser time to process. Give a delay to assigning <code>.target-fadein</code>:</p> <pre><code>window.setTimeout( function() { slides[targetIndex].className += " target-fadein"; }, 100 ); </code></pre> <p>Or put <code>.target-fadein-begin</code> into your HTML directly so it's parsed on load and will be ready for the transition.</p> <p>Adding <code>transition</code> to an element is not what triggers the animation, changing the property does.</p> <p>Demo: <a href="http://jsfiddle.net/ThinkingStiff/QNnnQ/" rel="noreferrer">http://jsfiddle.net/ThinkingStiff/QNnnQ/</a></p> <p>HTML: </p> <pre><code>&lt;div id="fade1" class="fadeable"&gt;fade 1 - works&lt;/div&gt; &lt;div id="fade2"&gt;fade 2 - doesn't work&lt;/div&gt; &lt;div id="fade3"&gt;fade 3 - works&lt;/div&gt; </code></pre> <p>CSS: </p> <pre><code>.fadeable { opacity: 0; } .fade-in { opacity: 1; transition: opacity 2s; -moz-transition: opacity 2s; -ms-transition: opacity 2s; -o-transition: opacity 2s; -webkit-transition: opacity 2s; } </code></pre> <p>Script:</p> <pre><code>//works document.getElementById( 'fade1' ).className += ' fade-in'; //doesn't work document.getElementById( 'fade2' ).className = 'fadeable'; document.getElementById( 'fade2' ).className += ' fade-in'; //works document.getElementById( 'fade3' ).className = 'fadeable'; window.setTimeout( function() { document.getElementById( 'fade3' ).className += ' fade-in'; }, 100); </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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