Search code examples
javascriptjqueryfancyboxlightboxfancybox-3

Fancybox 3 setTimeout?


I would like an internal URL to fire in Fancybox 3 around 5 seconds once the page has loaded. I have the following code however I just get loading PNG - nothing appears.

setTimeout(function(){
  $.fancybox.open({
    iframe : {
      href:'http://www.gamespot.com'
      }
    });
  }, 2000);

I'm not very smart with JS, though I believe it may clashing with some other code. Any advice before this Mac goes out the window?

Thanks :)


Solution

  • Check out samples from the documentation - http://fancyapps.com/fancybox/3/docs/#api and use correct syntax, something like this:

    setTimeout(function() {
      $.fancybox.open({
        type : 'iframe',
        src  : 'https://codepen.io/spark/',
        opts : {
          iframe : {
            preload : false
          }
        }
      });
    }, 2000);
    

    Demo - https://codepen.io/anon/pen/ooBZoK?editors=1010

    btw, you will not be able to include gamespot.com, because this site (like many others) prevents embedding.