简体   繁体   English

检查starSpin()是否已在运行,并在运行时使用stopSpin()将其停止

[英]Check if starSpin() is already running and stop it using stopSpin() in case it is running

I am using spin.js to show spinner before the data gets loaded on the screen. 我正在使用spin.js在数据加载到屏幕上之前显示微调框。 I have several tabs. 我有几个标签。 Everytime, i click on a tab, it shows spinner and i have kept stopSpin() inside the function so that when the data gets loaded, the spinner will stop. 每当我单击一个选项卡时,它就会显示微调框,并且我在函数内保留了stopSpin(),以便在加载数据时,微调框将停止。

This runs fine in normal condition. 在正常情况下,这可以正常运行。 User clicks tab -- Spinner starts -- Data gets loaded-- spinner stops. 用户单击选项卡-微调器启动-数据加载-微调器停止。

But when i click on a tab and at that moment click on other tab, the spinner keeps on spinning. 但是,当我单击一个选项卡,然后单击其他选项卡时,微调器将继续旋转。 This spinner is of the first tab i clicked. 该微调器是我单击的第一个选项卡。 It didnt let the complete function to run and when i clicked on other tab, the new spinner got loaded and stops. 它没有让完整功能运行,当我单击其他选项卡时,新的微调器加载并停止。 But the first tabs spinner continues to spin... 但是第一个选项卡微调器继续旋转...

Is there a way to check if i can see if the spinner is running initially and stop it if at all it is running. 有没有一种方法可以检查我是否可以看到微调器是否最初在运行,如果根本没有运行,请停止它。

**\\$("#rpt21 a.keepopen").click(function(){ \\$("#report_panel").html(""); \\$("#report_panel,#report_header,#report_panel_alldata,#report_header_alldata").hide(); ** \\ $(“#rpt21 a.keepopen”)。click(function(){\\ $(“#report_panel”)。html(“”); \\ $(“#report_panel,#report_header,#report_panel_alldata,#report_header_alldata “)。隐藏();

    $get_parameters;
    startSpin();
    x = getDataForRpt(rmanager,manager,account,folderdate,pricedate,"buy_list","$tmp_rpt_folder","$tmp_rpt","runRpt");
    \$("#report_panel").show();

});**

** **

    function getDataForRpt(rmanager,manager,account,folderdate,pricedate,rpt_name,tmp_folder,tmp_rpt,action)
    {

    var perlURL= "$thiscode"; 
    \$.ajax({       
        url:    perlURL,
        data:   {rmanager:  rmanager,
             manager:   manager,
             account:   account,
             folderdate:    folderdate,
             pricedate: pricedate,
             rpt_name:  rpt_name,
             tmp_folder:    tmp_folder,
             tmp_rpt:   tmp_rpt,
             action:    action
             },
        success: function(result) {
                          if(result.isOk == false){
                              alert("no data");}

                          //\$("#report_panel").load("$url_link/webtmp/$tmp_rpt");  

                  \$("#report_panel").html("<object data='$url_link/webtmp/$tmp_rpt' , type='text/html' width=97% height=100%></object>");
                  //\$("#report_panel").html('<object data="http://apmqa.mcm.com/webtmp/web_table_rpt.html" type="text/html" width=1000 height=500 ></object>');
    //\$("#report_panel").load("http://apmqa.mcm.com/webtmp/test_web_table_rpt.html");  
                          stopSpin();

                      },

         }); 


    }

** **

You can see here i have used start spin when a tab is clicked. 您可以在这里看到单击选项卡时我使用了启动旋转。 There are several functions like this and each has startSpin() in it. 像这样有几个函数,每个函数都有startSpin()。

The getDataForRpt is common. getDataForRpt是常见的。 So i have kept one stopSpin() there. 所以我在那里保留了一个stopSpin()。

I got the answer for this. 我得到了答案。 If anybody wants to know, here it is. 如果有人想知道,就在这里。

**function startSpin(){
startSpin.called = true;
var target = document.getElementById('spin_container');
var spinner = new Spinner(opts).spin(target);
\$('#spin_container').data('spinner', spinner);
}**

Insert startSpin.called = true; 插入startSpin。Called = true; in the main function and type below wherever we want the spinner to load. 在main函数中,然后在希望加载微调器的位置键入以下内容。 This way, it will check if spinner is active or not. 这样,它将检查微调器是否处于活动状态。 If active, it would stop original spinner first and then proceed with next function. 如果激活,它将首先停止原始微调器,然后继续下一个功能。

**if (startSpin.called){
stopSpin();`enter code here`

}** } **

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM