White flash when opening iframe Colorbox

2019-07-19 17:18发布

问题:

I get an white flash when opening an iframe colorbox. How can I prevend the iframe to first show the white background and then the supposed iframe?

回答1:

The white flash is the result of colorbox dynamically generating the iframe. While the iframe is loading you see the background color of the colorbox window itself.

One way to solve this issue is to use the "black" colorbox css styles as demonstrated in this jsfiddle. You can find this colorbox.css file in the "Example 3" folder when you download colorbox. Using this style you will of course see a black flash rather than and white flash, but it blends in better with the translucent black of the colorbox overlay.

Alternatively you can customize the colorbox.css file that's best suited to your needs. There's 5 prebuilt styles, which you can see demonstrated at the official colorbox site.



回答2:

Try passing fastIframe: false in the colorbox configuration. It makes colorbox wait until all contents of the iframe are loaded before attempting to show anything.

$('a').colorbox({ iframe: true, fastIframe: false });