Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement a sliding animation in javascript correctly?
    primarykey
    data
    text
    <p>In my pursuit to learn javascript I am making the same slider, but with the animation on javascript (using css it is not an issue for me - it was made on the site google), as the one below:</p> <p>Original Google slider (animation with css): <br/> <a href="http://www.google.com/about/datacenters/inside/" rel="nofollow">http://www.google.com/about/datacenters/inside/</a></p> <p><strong>My work so far:</strong></p> <p><a href="http://jsfiddle.net/TS7Xu/3/" rel="nofollow">http://jsfiddle.net/TS7Xu/3/</a></p> <pre><code>&lt;!-- language-all: lang-html --&gt; &lt;!DOCTYPE HTML&gt; &lt;html lang="en-US"&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;title&gt;&lt;/title&gt; &lt;style type="text/css"&gt; #promo{ display:block; height: 354px; width: 790px; } .promo-item { width: 81px; height: 354px; float: left; } .promo-item.wide { width: 613px; } .threeP { background-color: rgb(206, 203, 203); } .oneP { background-color: rgb(241, 220, 182); } .twoP { background-color: rgb(187, 217, 226); } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="promo"&gt; &lt;div class="promo-item twoP wide" id="twoP"&gt; &lt;div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="promo-item threeP" id="threeP"&gt; &lt;div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="promo-item oneP" id="oneP"&gt; &lt;div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; var oneP = document.getElementById('oneP'); var twoP = document.getElementById('twoP'); var threeP = document.getElementById('threeP'); step = 1; function expandPanel1(){ var h = oneP.clientWidth + step; oneP.style.width = h+"px"; if (h &lt; 614 || h !=614) { setTimeout("expandPanel1()", 5); } else { oneP.style.width = 613+"px"; } } function expandPanel2(){ var h = twoP.clientWidth + step; twoP.style.width = h+"px"; if (h &lt; 614 || h !=614) { setTimeout("expandPanel2()", 5) } else { twoP.style.width = 613+"px"; } } function expandPanel3(){ var h = threeP.clientWidth + step; threeP.style.width = h+"px"; if (h &lt; 614 || h !=614) { setTimeout("expandPanel3()", 5) } else { threeP.style.width = 613+"px"; } } //--------------------------------------------- function expandPanel1Minus(){ var h = oneP.clientWidth - step; oneP.style.width = h+"px"; if (h &gt; 80 || h !=80) { setTimeout("expandPanel1Minus()", 5) } else { oneP.style.width = 81+"px"; } } function expandPanel2Minus(){ var h = twoP.clientWidth - step; twoP.style.width = h+"px"; if (h &gt; 80 || h !=80) { setTimeout("expandPanel2Minus()", 5) } else { twoP.style.width = 81+"px"; } } function expandPanel3Minus(){ var h = threeP.clientWidth - step; threeP.style.width = h+"px"; if (h &gt; 80 || h !=80) { setTimeout("expandPanel3Minus()", 5) } else { threeP.style.width = 81+"px"; } } //--------------------------------------------- oneP.onmouseover = function () { expandPanel1() expandPanel3Minus() expandPanel2Minus() } twoP.onmouseover = function () { expandPanel2() expandPanel3Minus() expandPanel1Minus() } threeP.onmouseover = function () { expandPanel3() expandPanel2Minus() expandPanel1Minus() } &lt;/script&gt; </code></pre> <p> </p> <p>I know this example has errors because if a long drive with the mouse on the slider, it begins to "violently" run :) I deliberately lowered animation speed.</p> <p>Can someone give me some guidance on how to implement this correctly?</p>
    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.
 

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