在初始化叠加层之前加载所有内容

时间:2017-04-05 10:01:26

标签: jquery fancybox preload

嘿:)我有一个fancybox,包含内联内容和JavaScript生成的内容。当然,内联内容的加载速度要快得多,javascript需要一段时间。我可以实际在后台加载fancybox并隐藏它,然后在加载所有javascript后显示它吗?基本上预加载所有内容,然后打开它..没有真正破坏用户体验..

我的设置是这样的:

//making the splash_window visible after adding all components to it
splash_window.setVisible(true);

//Used to detect when the splash_window is visible to the user
if (splash_window.isShowing()){

    //Used to know if the splash_window is visible
    System.out.print("Splash screen is complete and now visible." + System.lineSeparator());

    //Method used to increase my progress by 5%
    initProgress.setValue(getProgress(5));

    //Other commands...
}

我的javascript:

 Add-Migration Initial -IgnoreChanges then Update-Database

1 个答案:

答案 0 :(得分:0)

只需打包代码,在某些函数中打开fancybox,而不是在生成""之后从javascript调用它。

<script type="text/javascript">
    function openPopup() {
            $.fancybox.open([
                {
                    type: 'inline',
                    href : '.popupContent',              
                }
            ], {
                closeClick: false,
                fitToView: true,
                autoResize: true,
                closeBtn: false,
                hideOnContentClick: true,
                hideOnOverlayClick: false,
                autoSize: true,
                openSpeed: 150,
                modal: true,
                padding : 0
            });
        });

 </script>

<div id="something_js_generated">
      <script> 
      //generate something
      openPopup();
      </script>
</div>

或许您的生成代码可以在完成后触发某些事件。比你可以将开场功能绑定到事件。像这样:

<script type="text/javascript">
         $( document).on( "myCustomEventsPrefix:OpenPopup",function(){
              $.fancybox.open(
                 //....
               );
         });

     </script>

    <div id="something_js_generated">
          <script> 
          //generate something
          $(document).trigger( "myCustomEventsPrefix:OpenPopup");
          </script>
    </div>