如何在Javascript上显示延迟时间

时间:2018-01-07 15:08:18

标签: javascript

这是使按钮可见的代码,我想显示延迟时间。我该怎么表现出来?



{{1}}

{{1}}




1 个答案:

答案 0 :(得分:0)



#skip{
  display:none
 }

<label id="countdown"style="float:Right"></label>
<a href="#" style="float:Right" id="skip">
    <i class="fas fa-caret-right fa-lg"></i>
    Skip
 </a> 
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
  $(document).ready(function() {
    var countdown =  $('#countdown');
    var counter = 11;
    var idTimeout = 0;
    
    idTimeout = setInterval (function (item){
        countdown.text(--counter);
    },1000);  
    
     //convert delay in promise to detect when delay is  finished   
     var delayDone =  $('#skip')
                          .hide()
                          .delay(10000)     
                          .promise();
    //when delay is done by function then() we can appply our code
     delayDone.then(function(){
        clearTimeout(idTimeout);
        countdown.fadeOut('fast'); 
        //"this" refers to  $('#skip') which on the top ..
        //...of the JQUERY chain call
        this.fadeIn(2200);//==  $('#skip').fadeIn(2200);
     });    
     
    });
    
</script>
&#13;
&#13;
&#13;