Plain Page Flip Effect
Declare variables in the smallest possible scope

It's recommended to declare variables in the smallest scope where they are needed.
That way, the variable will not be visible where it should not be,
and therefore it cannot be modified accidentally by mistake.
It also makes understanding a program easier when you don't need to keep more variables in your head than necessary.

Therefore, since most of the variables are not needed in the global scope,
move those declarations to the functions that need them.

Be careful with variable scope in JavaScript.
Looking at this code,
you may be mislead that the variable i is only visible within the loop:


  for (var i = section.length - 1; i &gt;= 0; i--) {
    section[i].style.position = "fixed";
  }



But that's not the case. The variable is visible after the loop,
and even before the loop (with value undefined).

In this particular example you want to replace the var with the let keyword,
if your version of JavaScript supports it (like any non-ancient implementation).
Using let, the variable will only be visible within the loop.

Avoid redundant variable initializations

In the posted code all variables are initialized at the time of declaration.
But if the variables don't need an initial value, then this is just noise.

Order conditional terms by their values

It can improve readability when the terms in conditionals are in a consistent order. Take for example this piece:


  if (y &gt;= 0 &amp;&amp; y &lt; h) {
    // ...
  }
  if (y &gt;= h &amp;&amp; y &lt; h * 2) {
    // ...
  }



The first condition means y is between 0 and h,
and the second means y is between h and h * 2.
Although this is easy enough to see,
the current writing style doesn't really help to see it.

Consider this alternative:

  if (0 &lt;= y &amp;&amp; y &lt; h) {
    // ...
  }
  if (h &lt;= y &amp;&amp; y &lt; h * 2) {
    // ...
  }


Now, the meaning hasn't changed, but it's much easier to see.
And with this writing style,
it's also easier to see that the two conditions will not be true at the same time,
so the second if should in fact be an else if.