Single formpdf

So that’s why you see the flicker of the form in its original position before the ever-so-slightly-delayed function runs and moves the 

 into the lightbox.[2]

All other things being equal, #1 would be better, since you can manage browser behaviors (like lightbox()-ing) separately from loading the form from the server.

Single formmeaning

Then hide forms with that attribute by default, only showing them after they’re moved inside the modal container (i.e. lightbox):

United Nations building

But even if it takes the absolute minimum of 4ms, the browser still schedules a new task, “turning” the JavaScript event loop. And since the initial task has completed (the one that ends with the call to setTimeout) the browser takes the opportunity to repaint the window.

Note the behavior of #1 is the same whether whenReady() comes before or after loadForm(). I just put it before so you wouldn’t be tempted to think that was the cure.

Instead, whenReady listeners fire asynchronously.There are actually 2 different async modes[1], but they’re both equivalent (for today’s purposes) to:

setTimeout with a delay of 0, as you may already know, doesn’t really mean a delay of zero milliseconds. It means 4ms + whatever additional time the browser needs to schedule a new task. So it might be just 4ms or a few millis more, maybe even a few seconds if other tasks are going crazy in the browser at that moment.

Single formonline

Luckily, you can avoid the flicker in all cases with a little CSS. When creating the shell  element, add a special attribute:

Single formapp

Let’s say you want to immediately switch to lightbox mode (using the Forms 2.0 native lightbox() feature) when a specific form is ready.

. Please enter the desired qty for the material(s) you want to include in your promotion or Proceed Without Promotion and only your base materials will be added to the cart.

In #1, the callback function technically runs when any form becomes ready, but the lightbox is conditioned on the form ID. (For a page with only one form, that condition wouldn’t be necessary.)

The way an onSingleFormReady callback works — it doesn’t have that official name, it’s really just “the 4th argument to loadForm” — is that immediately after the form is rendered, the callback runs. “Immediately” meaning on the very next line, in the same execution context:

You might not ever notice this difference, of course. 99.999% of form behaviors (which you should be adding using whenReady, by the way!) don’t need to repaint the screen. The lightbox is a notable exception because the  element is relocated in the DOM.