setInterval not working properly on Chrome

前端 未结 4 712
轻奢々
轻奢々 2020-11-30 07:11

I have a custom made slideshow object to perform the usual stuff the name indicates on a website. It all works well except when I switch tabs in Chrome and come back to the

4条回答
  •  再見小時候
    2020-11-30 07:25

    There was a similar problem with chrome

    As I have solved this problem. At the start, write down mktime variable, and then simply subtracted from the current time. Example:

    var values = {};
    
    function mktime(){
     var date = new Date();
     return Math.floor(date.getTime()/1000);
    }
    function getTime(string){
      var splitContent = string.split(/\:/g);
      var hours = parseInt(splitContent[0]) * 60 * 60;
      var minutes = parseInt(splitContent[1]) * 60;
      var seconds = parseInt(splitContent[2]);                          
      return hours + minutes + seconds;
    }
    function startTimer(time){
    
     values.startMkTime = mktime();
     values.startTime = getTime(time);
     setInterval(process(),1000);                       
    }
    
    function process(){
       values.currentTime = (mktime() - values.startMkTime) +       o.values.startTime;//new code
    }
    

提交回复
热议问题