Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well you have only two actions in your code, but much too many conditions. Use a single if-else-statement, and boolean operators in the condition. If that was impossible, you could at least</p> <ul> <li>remove the empty lines to get the full logic on one screen page</li> <li>add some comments on what the branches are doing (and why)</li> <li>avoid early returns</li> </ul> <p>Here's your function simplified:</p> <pre><code>var duration = +new Date() - start.time, isPastHalf = Number(duration) &lt; 250 &amp;&amp; Math.abs(delta.x) &gt; 20 || Math.abs(delta.x) &gt; viewport / 2, isFarRight = this.content.getBoundingClientRect().left &gt; viewport / 2, direction = delta.x &lt; 0; if (!isScrolling) { if (isPastHalf) { if (direction) this.close(); else { if (isFarRight &amp;&amp; pulled) this.close(); else this.open(); } } else { if (isFarRight) { // Looks like the opposite of `direction`, is it? if (this.isEmpty(delta) || delta.x &gt; 0) this.close(); else this.open(); } else this.close(); } } </code></pre> <p>and shortened:</p> <pre><code>var duration = +new Date() - start.time, isPastHalf = Number(duration) &lt; 250 &amp;&amp; Math.abs(delta.x) &gt; 20 || Math.abs(delta.x) &gt; viewport / 2, isFarRight = this.content.getBoundingClientRect().left &gt; viewport / 2, direction = delta.x &lt; 0, undirection = this.isEmpty(delta) || delta.x &gt; 0; if (!isScrolling) { if ( isPastHalf &amp;&amp; ! direction &amp;&amp; !(isFarRight &amp;&amp; pulled) || !isPastHalf &amp;&amp; !undirection &amp;&amp; isFarRight ) this.open(); else this.close(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    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