如何在0秒左右隐藏计时器

时间:2022-07-10 02:49:39

im having problems with removing the active classes and adding the hidden classes when the timer is at 0minutes and 0 seconds. it is supposed to be used on tablets so i recommend inspecting elements and make a smaller browser if you want to test it.

我在删除活动类时遇到问题,并在计时器为0分钟和0秒时添加隐藏类。它应该在平板电脑上使用,所以我建议检查元素并制作一个较小的浏览器,如果你想测试它。

var interval;

function countdown() {
  clearInterval(interval);
  interval = setInterval( function() {
      var timer = $('.js-timeout').html();
      timer = timer.split(':');
      var minutes = timer[0];
      var seconds = timer[1];
      seconds -= 1;
      if (minutes < 0) return;
      else if (seconds < 0 && minutes != 0) {
          minutes -= 1;
          seconds = 59;
      }
      else if (seconds < 10 && length.seconds != 2) seconds = '0' + seconds;

      $('.js-timeout').html(minutes + ':' + seconds);

      if (minutes == 0 && seconds == 0) clearInterval(interval);

      if (minutes === 0 && seconds === 0) {
         $('#gaop').removeClass('hidden').addClass('active');
            $('#beeindig').addClass('hidden').removeClass('active');
            $('#timer').addClass('hidden').removeClass('active');
            $('#knop').removeClass('begin-date').removeClass('shake');
            $('#knop-deel2').removeClass('begin-date').removeClass('shake');
            
      }



  }, 1000);
}

// $('#js-startTimer').click(function () {
//   $('.js-timeout').text("2:00");
//   countdown();
// });


// $('#js-resetTimer').click(function () {
//   $('.js-timeout').text("2:00");
//   clearInterval(interval);
// });





	$('.activate-date').click(function() {
        
        if ($('#gaop').hasClass('active')) {
           
            $('#gaop').removeClass('active').addClass('hidden');

            $('#beeindig').removeClass('hidden').addClass('active');

             $('#timer').removeClass('hidden').addClass('active');

            $('#knop').addClass('begin-date').addClass('shake');

            $('#knop-deel2').addClass('begin-date').addClass('shake');

            $('.js-timeout').text("2:00");
            countdown();

            

           



        } else {
            
            $('#gaop').removeClass('hidden').addClass('active');
            $('#beeindig').addClass('hidden').removeClass('active');
            $('#timer').addClass('hidden').removeClass('active');
            $('#knop').removeClass('begin-date').removeClass('shake');
            $('#knop-deel2').removeClass('begin-date').removeClass('shake');
            $('.js-timeout').text("2:00");
            clearInterval(interval);


        }
            
          
        
    }); 
div.wrapper{
    position: relative;
    
}

div.center{

position: absolute;
    left: 0;
    right: 0;
    top: 0;
    position: fixed;

}

.activate-date {
    border: 4px solid grey;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    position: fixed;
    left: 0;
    right: 0;
    margin-left: auto;
    margin-right: auto;
    top: 35%;
    z-index: 3;
}
p.text-hint{
    font-family: 'Opensans-regular';
    color: black;
    font-weight: 120%;
    font-size: 1.5em;
    text-align: center;
    margin: 0 auto;
    /*position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;*/
    position: fixed;
    top: 40%;
    left: 0;
    right: 0;
}

div.center div.text-timer{
    font-family: 'Opensans-regular';
    color: black;
    font-weight: 120%;
    font-size: 0.9em;
    text-align: center;
    margin: 0 auto;
    /*position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;*/
    position: fixed;
    top: 42%;
    left: 0;
    right: 0;

}


.active{
    display: block;
}

.hidden{

    display: none;
}


#knop {

	margin: 0px auto;
    height: 400px;
	width: 400px;
    border: 10px solid white;
    border-radius: 50%;
    -webkit-box-shadow: 0 0px 60px white,
             inset 0 0 60px white;
       -moz-box-shadow: 0 0px 60px white,
            inset 0 0 60px white;
            box-shadow: 0 0px 60px white,
            inset 0 0 60px white;
            text-align: center;
    margin-top: 35%;
	}

#knop-deel2{
    margin: 0px auto;
    height: 400px;
    width: 400px;
    border: 10px solid white;
    border-radius: 50%;
    -webkit-box-shadow: 0 0px 60px white,
             inset 0 0 60px white;
       -moz-box-shadow: 0 0px 60px white,
            inset 0 0 60px white;
            box-shadow: 0 0px 60px white,
            inset 0 0 60px white;
            text-align: center;
    margin-top: 35%;

    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    position: fixed;

}
<div class="center">
	    	<div class="activate-date"></div>
	        <div id="knop" class="animated ring-binnen"></div>
	    	<div id="knop-deel2" class="animated ring-buiten"></div>
	    	<p id="gaop" class="text-hint active" readonly>Ga op blind meeting</p>
	        <p id="beeindig"  class="text-hint hidden" readonly>Beeindig meeting</p>
	        

	        <div id="timer" class="text-timer hidden"><p>de meeting eindigt in <span class="js-timeout">2:00</span> minuten.</p>

			
	    </div>

1 个解决方案

#1


0  

Actually you are converting your second value to string '0'+seconds, which is not equal to 0, so either do it like

实际上你正在将你的第二个值转换为字符串'0'+秒,这不等于0,所以要么像它一样

if (minutes <= 0 && seconds == "00") clearInterval(interval);
if (minutes <= 0 && seconds == "00") {

}

or do it like

或者喜欢

seconds = parseInt(seconds, 10);
if (minutes <= 0 && seconds == 0) clearInterval(interval);
if (minutes <= 0 && seconds == 0) {

}

#1


0  

Actually you are converting your second value to string '0'+seconds, which is not equal to 0, so either do it like

实际上你正在将你的第二个值转换为字符串'0'+秒,这不等于0,所以要么像它一样

if (minutes <= 0 && seconds == "00") clearInterval(interval);
if (minutes <= 0 && seconds == "00") {

}

or do it like

或者喜欢

seconds = parseInt(seconds, 10);
if (minutes <= 0 && seconds == 0) clearInterval(interval);
if (minutes <= 0 && seconds == 0) {

}