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.

            
              <!-- hyperlinks: target="_blank" for codepen.io -->
  <audio id="alarm" class="hidden-xs-up" controls="" loop="true">
    <source src="https://github.com/gregorywong/sandbox/raw/gh-pages/freeCodeCamp/pomodoro/audio/beep.ogg" type="audio/ogg"/>
    <source src="https://github.com/gregorywong/sandbox/raw/gh-pages/freeCodeCamp/pomodoro/audio/beep.mp3" type="audio/mpeg"/>
    Your browser does not support the audio element.
  </audio>

  <div class="container h-100">
    <div class="row h-100 justify-content-center align-items-between">
      <div class="col-12 text-center">
        <h1 class="text-red title mt-2">Pomodoro</h1>
      </div>
      <div class="col-12 text-center my-auto pt-2">

        <div class="d-flex justify-content-center">
          <div class="">
            <input id="minutes" class="text-center display time-input" type="number" name="" value="25" />
          </div>
          <div class="my-auto">
            <h1 class="display">:</h1>
          </div>
          <div class="">
            <input id="seconds" class="text-center display time-input" type="number" name="" value="00" />
          </div>
        </div>

        <div class="mt-2 mt-sm-3 mt-md-4 text-center">
          <button id="start-stop-button" class="btn-mod btn-warning start-stop-button" type="button" name="button">START / STOP</button>
        </div>
      </div>

      <div class="text-center text-white mt-auto w-100 pb-4 credits">
        <p>Designed and Coded by <a class="text-warning" href="http://www.gregwong.me" target="_blank">Greg Wong</a></p>
      </div>
    </div>
  </div>
            
          
!
            
              html, body {
  position: relative;
  height: 100%;
}

body {
  background: url('https://github.com/gregorywong/sandbox/raw/gh-pages/freeCodeCamp/pomodoro/tomato.jpg') no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

/* so that the background doesn't affect the look of the app on very small screens */
@media (max-height: 480px) and (max-width: 675px) {
  body {
    background-size: auto 480px;
    background-attachment: scroll;
  }
}

.text-red {
  color: red;
}

.title {
  font-family: 'Monoton', cursive;
  text-shadow: 0 0 2px #000;
}

.credits {
  font-family: 'Special Elite', cursive;
  text-shadow: 0 0 2px #000;
}

.start-stop-button {
  font-family: 'Cabin Sketch', cursive;
  font-size: 1.5em;
  color: black;
  border-radius:25px;
}

.btn-mod:active {
  background-color: orange;
  color: red;
  transform: translateY(3px);
}

.btn-mod:focus {
  /* modifies default behavior of outlining buttons upon being clicked */
  outline: 0 none!important;
  box-shadow: none;
}

input {
  background: transparent;
  width: 1.8em;
  font-family: monospace;
  font-size: 4em;
  border: 0;
  border-top: 3px solid black;
  border-bottom: 3px solid black;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    /* display: none; <- Crashes Chrome on hover */
    -webkit-appearance: none !important;
    margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
}

input:hover {
  color: orange;
  border-color: orange;
  text-shadow: 0 0 1px #000;
}

input:focus {
  color: yellow;
  border-color: yellow;
}

input:focus {
  outline: 0 none!important;
}

.display {
  font-family: 'Monoton', cursive;
}

            
          
!
            
              var CountDown = function(sec, tickCallback, timesUpCallback) {
  const MAX_SEC = 5999;
  var setSeconds = sec;
  validateSetSeconds(); // change it to a suitable value if necessary
  var seconds = setSeconds;
  var timerID = null;
  var tickCallback = tickCallback;
  var timesUpCallback = timesUpCallback;
  var alarmOn = false;
  const INTERVAL = 1000;

  this.set = function(sec) {
    if (!timerID) { // can't set it while it's running
      setSeconds = sec;
      validateSetSeconds();
      seconds = setSeconds;
    }
  };

  this.start = function() {
    if (!timerID) {
      // if timer has just gone off, reset it to the previously set time
      if (seconds <= 0) {
        seconds = setSeconds;
      }
      timerID = setInterval(tick, INTERVAL);
    }
  };

  this.stop = function() {
    stop();
    alarmOn = false;
  };

  this.isRunning = function() {
    return timerID != null;
  };

  this.isAlarmOn = function() {
    return alarmOn;
  };

  this.getSetSeconds = function() {
    return setSeconds;
  };

  function validateSetSeconds() {
    setSeconds = Math.floor(setSeconds); // in case a float was passed in
    if (setSeconds < 0) {
      setSeconds = 0;
    }
    else if (setSeconds > MAX_SEC) {
      setSeconds = MAX_SEC;
    }
  }

  function tick() {
    seconds--;
    if (seconds <= 0) {
      seconds = 0; // don't display negative values
      timesUpCallback();
      alarmOn = true;
      stop();
    }
    tickCallback(seconds);
  }

  function stop(){
    if (timerID) {
      clearInterval(timerID);
      timerID = null;
    }
  }
};

function getMinutesAndSeconds(sec) {
  // return seconds in MM:SS format
  var minutes = Math.floor(sec / 60);
  minutes = minutes < 10 ? '0'+ minutes : minutes;
  var seconds = sec % 60;
  seconds = seconds < 10 ? '0'+ seconds : seconds;

  return [minutes, seconds];
}

function toSeconds(minutes, seconds) {
  return minutes * 60 + seconds;
}

function getSuitableMinutes(min) {
  if (min < 0) {
    return 0;
  }
  else if (min > 99) {
    return 99;
  }
  return min;
}

function getSuitableSeconds(sec) {
  if (sec < 0) {
    return 0;
  }
  else if (sec > 59) {
    return 59;
  }
  return sec;
}

$(document).ready(function() {

  var alarm = document.getElementById("alarm");
  var alarmIntervalID;
  function flashTimer() {
    $(".display").stop().css("color", "yellow").animate({color: "black"}, 1000, stopFlash);
  }

  function stopFlash() {
    $(".display").removeAttr('style'); // this works as I do not define styles in the html file
  }

  var updateDisplay = function(sec) {
    var time = getMinutesAndSeconds(sec);
    $("#minutes").val(time[0]);
    $("#seconds").val(time[1]);
  };

  var timesUp = function() {
    alarm.play();
    flashTimer();
    alarmIntervalID = setInterval(flashTimer, 1000);
  };

  var myCountDown = new CountDown(toSeconds(25,0), updateDisplay, timesUp);

  $(".time-input").focusin(function(event) {
    alarm.pause(); // if it's not playing, this won't do anything
    alarm.load();
    clearInterval(alarmIntervalID);
    myCountDown.stop();
  });

  $(".time-input").focusout(function(event) {
    var minutes = parseInt($("#minutes").val());
    var seconds = parseInt($("#seconds").val());

    if (!minutes) {
      minutes = 0;
    }
    if (!seconds) {
      seconds = 0;
    }

    minutes = getSuitableMinutes(minutes);
    seconds = getSuitableSeconds(seconds);

    var sec = minutes * 60 + seconds;
    updateDisplay(sec);
    myCountDown.set(sec);
  });

  $("#start-stop-button").click(function(event) {
    if (myCountDown.isAlarmOn()) {
      alarm.pause();
      alarm.load();
      clearInterval(alarmIntervalID);
      myCountDown.stop();
      updateDisplay(myCountDown.getSetSeconds());
    }
    else if (myCountDown.isRunning()) {
      myCountDown.stop();
    }
    else {
      myCountDown.start();
    }
  });

});

            
          
!
999px
Loading ..................

Console