cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <h1 class="text-center text-success">Pomodoro Timer</h1>
<div class="time-set-container">
  <div class="time-set col-*-1">
    <p>Work Time</p>
    <i class="glyphicon glyphicon-menu-up" id="pom-up"></i>
    <br>
    <span id="pom-time"></span>
    <br>
    <i class="glyphicon glyphicon-menu-down" id="pom-down"></i>
  </div>
  <div class="time-set">
    <p>Break Time</p>
    <i class="glyphicon glyphicon-menu-up" id="break-up"></i>
    <br>
    <span id="break-time"></span>
    <br>
    <i class="glyphicon glyphicon-menu-down" id="break-down"></i>
  </div>
</div>

<div id="timer-box">
  <div id="progress"></div>
  <div id="timer" class="text-center">00:00:00</div>
</div>
<p id="status" class="text-center"> Working</p>
<div class="button-container">
  <button class="btn btn-success" id="start">Start</button>
  <button class="btn btn-warning" id="stop">Stop</button>
  <button class="btn btn-danger" id="reset">Reset</button>
</div>


            
          
!
            
              body {
  background: tan;
  color: white;
}

h1 {
  font-size: 33px;
  font-family: Arial;
  color: white;
}

button {
  display: inline-block;
  margin: 0 15px;
}

#timer-box {
  height: 75px;
  width: 375px;
  margin: 0 auto;
  border: white 1px solid;
  
}

.work {
  background: green;
}

.break {
  background: red;
}

#timer {
  padding-left: 75px;
  position: absolute;
  font-size: 56px;
}

i {
  cursor: pointer;
}

.button-container {
  text-align: center;

}

.time-set {
  text-align: center;
  margin: 15px 25px;
  display: inline-block;
  font-size: 18px;
}

.time-set-container {
  text-align: center;
}

#progress {
  float: right;
  background-color: green;
  height: 100%;
  width: 0%;
}

#status {
  color: green;
  padding: 15px;
  font-size: 18px;
}
            
          
!
            
              $(document).ready(function() {
  "use ";
  var time = {
    count: 15*60,
    initial: 15*60,
    pom: 15*60,
    break: 5*60,
    running: false
  };
  var workOrBreak = "work";
  var counter = setInterval(timer, 1000);
  updateTimes();

  function cycleTimer() {
    if (workOrBreak == "work") {
      workOrBreak = "break";
      time.count = time.break;
      time.initial = time.break;
      $("#status").css("color", "red");
      $("#status").empty().append("Taking a break");
      $("#progress").css("background-color", "red");
      stopTimer();
      startTimer();
    } else {
      workOrBreak = "work";
      time.count = time.pom;
      time.initial = time.pom;
      $("#status").css("color", "green");
      $("#status").empty().append("Working");
      $("#progress").css("background-color", "lightgreen");
      stopTimer();
      startTimer();
    }
  }

  $("#start").click(function() {
    startTimer();
  });

  $("#stop").click(function() {
    stopTimer();
  });

  $("#reset").click(function() {
    workOrBreak = "work";
    time.count = time.pom;
    time.initial = time.pom;
    $("#status").css("color", "green");
    $("#status").empty();
    $("#status").append("Working");
    $("#progress").css({
      "background-color": "green",
      "width": "100%"
    });
    drawTimer();
  });

  $("#pom-up").click(function() {
    time.pom += 60;
    updateTimes();
  });

  $("#pom-down").click(function() {
    if (time.pom > 60) {
      time.pom -= 60;
    }
    updateTimes();
  });

  $("#break-up").click(function() {
    time.break += 60;
    updateTimes();
  });

  $("#break-down").click(function() {
    if (time.break > 60) {
      time.break -= 60;
    }
    updateTimes();
  });

  function timer() {
    time.count -= 1;
    if (time.count <= 0) {
      clearInterval(counter);
      cycleTimer();
    }
    drawTimer();
    $("#progress").css("width", time.count / time.initial * 100 + "%");
  }

  function startTimer() {
    console.log(workOrBreak);
    if (time.running === false) {
      counter = setInterval(timer, 1000);
      time.running = true;
    }
  }

  function stopTimer() {
    clearInterval(counter);
    time.running = false;
  }

  function updateTimes() {
    $("#pom-time").empty().append(time.pom / 60);
    $("#break-time").empty().append(time.break / 60);
  }

  function drawTimer() {
    $("#timer").empty();
    $("#timer").append(time.count.toHHMMSS());
  }

  Number.prototype.toHHMMSS = function() {
    var sec_num = parseInt(this, 10); // don't forget the second param
    var hours = Math.floor(sec_num / 3600);
    var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
    var seconds = sec_num - (hours * 3600) - (minutes * 60);
    if (hours < 10) {
      hours = "0" + hours;
    }
    if (minutes < 10) {
      minutes = "0" + minutes;
    }
    if (seconds < 10) {
      seconds = "0" + seconds;
    }
    var time = hours + ':' + minutes + ':' + seconds;
    return time;
  };

});
            
          
!
999px
Loading ..................

Console