Preload JQuery UI tabs in the background

前端 未结 2 1957
隐瞒了意图╮
隐瞒了意图╮ 2021-01-01 01:38

All,

How can I preload all JQuery UI tabs while the first tab is still loading? I have tried the remote:true option, but it didnt work? There should be ajax spinners

相关标签:
2条回答
  • 2021-01-01 02:11

    More elegant solution than above:

    $tabs = $('#tabs').tabs({
        cache : true,
        load : function(event,ui) {
            try {
                $tabs.tabs('load',ui.index+1);
            } catch (e) {
            }
        }
    });
    
    0 讨论(0)
  • 2021-01-01 02:25

    Try something like this:

    $tabs = $('#tabs').tabs({
        cache: true
    });
    var total = $tabs.find('.ui-tabs-nav li').length;
    var currentLoadingTab = 1;
    $tabs.bind('tabsload',function(){
        currentLoadingTab++;
        if (currentLoadingTab < total)
            $tabs.tabs('load',currentLoadingTab);
        else
            $tabs.unbind('tabsload');
    }).tabs('load',currentLoadingTab);
    

    It initializes the tabs with the cache option so that tabs aren't reloaded after they have been loaded once. It then finds out the total number of tabs and sets the next tab to load as 1 (tabs are indexed starting with 0 ) Then it binds an event on the load event to start loading the next tab until it has hit all of them. To start it of it then loads the second tab.

    0 讨论(0)
提交回复
热议问题