Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I used <a href="https://stackoverflow.com/a/16488235/227299">moredemons's</a> answer as a basis, <a href="http://www.uselesspickles.com/triangles/" rel="nofollow noreferrer">using CSS triangles</a>. It does the same thing, but it properly separates the CSS so you don't have to edit the JS to edit the colors. The JS is also simpler, doesn't rely on <code>if/elses</code> for all 16 states. </p> <p>The main benefit of a programatic solution over a gif is that you can customize the colors, sizes, animation rate more easily.</p> <ul> <li><a href="http://jsfiddle.net/mendesjuan/WYKmQ/10" rel="nofollow noreferrer">Small, green, blue, fast</a></li> <li><a href="http://jsfiddle.net/mendesjuan/WYKmQ/8/" rel="nofollow noreferrer">Big, red, blue, slow</a> </li> <li><a href="http://jsfiddle.net/mendesjuan/WYKmQ/6/" rel="nofollow noreferrer">Big with a different arrangement</a></li> </ul> <p><strong>Initial HTML</strong> All triangles hidden</p> <pre><code>&lt;div id ="ct" &gt; &lt;div class="triangle triangle-nw triangle-hide-tr triangle-hide-bl"&gt;&lt;/div&gt; &lt;div class="triangle triangle-ne triangle-hide-tl triangle-hide-br"&gt;&lt;/div&gt; &lt;br/&gt; &lt;div class="triangle triangle-sw triangle-hide-tl triangle-hide-br"&gt;&lt;/div&gt; &lt;div class="triangle triangle-se triangle-hide-tr triangle-hide-bl" &gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>CSS</strong></p> <pre><code>.triangle { font-size:0; border: 50px solid transparent; display: inline-block; width: 0; height: 0; margin:0; padding: 0; } .triangle-se { border-color: red red blue blue; } .triangle-sw { border-color: red blue blue red; } .triangle-nw { border-color: blue blue red red; } .triangle-ne { border-color: blue red red blue; } .triangle-hide-tl { border-top-color: transparent; border-left-color: transparent; } .triangle-hide-tr { border-top-color: transparent; border-right-color: transparent; } .triangle-hide-br { border-bottom-color: transparent; border-right-color: transparent; } .triangle-hide-bl { border-bottom-color: transparent; border-left-color: transparent; } </code></pre> <p><strong>JS</strong></p> <pre><code>setInterval((function(){ var index = 0; // Which square is going to be modified in each stage (16 stages) var map = [3,3,2,2,0,0,1,1,3,3,2,2,0,0,1,1]; // The clases to add and remove var classesToChange = ['tr', 'bl', 'br', 'tl', 'bl', 'tr', 'tl', 'br']; return function() { var el = $('#ct div.triangle').eq(map[index]); if (index &lt; 8) { // Showing pieces el.removeClass('triangle-hide-' + classesToChange[index] ); } else { // Hiding pieces el.addClass('triangle-hide-' + classesToChange[index - 8] ); } index++; if (index &gt;= 16) { index = 0; } }; })(), 200); </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