2016-12-15 18 views
0

我可以啓動微調器,但不知道如何停止它。請幫助:使用javaScript停止微調器 - SpinJs

//On button click load spinner and go to another page 
 
$("#btn1").click(function() { 
 
//Loads Spinner 
 
$("#loading").fadeIn(); 
 
var opts = { 
 
    lines: 12, // The number of lines to draw 
 
    length: 7, // The length of each line 
 
    width: 4, // The line thickness 
 
    radius: 10, // The radius of the inner circle 
 
    color: '#000', // #rgb or #rrggbb 
 
    speed: 1, // Rounds per second 
 
    trail: 60, // Afterglow percentage 
 
    shadow: false, // Whether to render a shadow 
 
    hwaccel: false // Whether to use hardware acceleration 
 
}; 
 
var trget = document.getElementById('loading'); 
 
var spnr = new Spinner(opts).spin(trget); 
 
}); 
 

 
$("#btn2").click(function() {  
 
    //Write code to stop spinner 
 

 
});
<button id="btn1">Start</button> 
 
<button id="btn2">Stop</button> 
 

 
<div id="loading"> 
 
<div id="loadingcont"> 
 
    <p id="loadingspinr"> 
 
    </p> 
 
</div> 
 
</div> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.3.2/spin.min.js" type="text/javascript"></script>

Refernces:

http://spin.js.org/
Stop Spinner.js

+0

什麼是停止微調平均值。無論你想隱藏它還是停止它的旋轉。 –

+0

任何事情,但用戶一定不能看到它。它應該在第二次點擊時消失。 – Deadpool

回答

1

使用此代碼。

$("#btn2").click(function() {  
    //Write code to stop spinner 
    $('#loading').fadeOut(); 

}); 
1

就摧毀它,例如 - 它會消失

$("#btn2").click(function() {  
    document.getElementById('loading').innerHTML=''; 
}); 
+0

好的。有效。 – Deadpool

1
$(trget).data('spinner', spnr); 
$('loading').data('spinner').stop(); 
1

//On button click load spinner and go to another page 
 
$("#btn1").click(function() { 
 
//Loads Spinner 
 
$("#loading").fadeIn(); 
 
var opts = { 
 
    lines: 12, // The number of lines to draw 
 
    length: 7, // The length of each line 
 
    width: 4, // The line thickness 
 
    radius: 10, // The radius of the inner circle 
 
    color: '#000', // #rgb or #rrggbb 
 
    speed: 1, // Rounds per second 
 
    trail: 60, // Afterglow percentage 
 
    shadow: false, // Whether to render a shadow 
 
    hwaccel: false // Whether to use hardware acceleration 
 
}; 
 
var trget = document.getElementById('loading'); 
 
var spnr = new Spinner(opts).spin(trget); 
 
}); 
 

 
$("#btn2").click(function() {  
 
    //Write code to stop spinner 
 
    $('#loading').fadeOut(); 
 
});
<button id="btn1">Start</button> 
 
<button id="btn2">Stop</button> 
 

 
<div id="loading"> 
 
<div id="loadingcont"> 
 
    <p id="loadingspinr"> 
 
    </p> 
 
</div> 
 
</div> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.3.2/spin.min.js" type="text/javascript"></script>

0

使var spnr用於訪問這兩種功能,

spnr = new Spinner(opts).spin(trget); 


---------- 

$("#btn2").click(function() {  
    //Write code to stop spinner 
    spnr.stop(); 
});