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 Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

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.

            
              <div class="clock no-select">

  <h1 class="no-select" onclick="ping.play();">Pomodoro Timer</h1>

  <div class="settings">

    <div class="break no-select">

      <h3 class="no-select">Break Length</h3>

      <div class="break-selector">

        <div class="break-minus no-select" onclick="subtractFromBreak();">-</div>

        <div class="break-value no-select" data-time="5" data-seconds="300">5</div>

        <div class="break-plus no-select" onclick="addToBreak();">+</div>

      </div>

    </div>

    <div class="session no-select">

      <h3 class="no-select">Session Length</h3>

      <div class="session-selector no-select">

        <div class="session-minus no-select" onclick="subtractFromSession();">-</div>

        <div class="session-value no-select" data-time="25">25</div>

        <div class="session-plus no-select" onclick="addToSession();">+</div>

      </div>

    </div>

  </div>

  <div class="timer">

    <h2>Session</h2>

    <div class="count">

      <div class="count-timer" data-time="25" data-seconds="1500">25</div>

    </div>

  </div>

</div>
            
          
!
            
              body {
  background-color: #313030;
  color: white;
}

.breakTime {
  background-color: #0f1;
  color: black;
}

.clock {
  max-width: 600px;
  margin: auto;
}

h1 {
  font-size: 70px;
  text-align: center;
  cursor: pointer;
}

.session,
.break {
  display: inline-block;
  width: 49%;
  text-align: center;
}

.break-selector > div,
.session-selector > div {
  display: inline-block;
  width: 70px;
  text-align: center;
  font-weight: bold;
  font-size: 30px;
  font-family: monospace;
  border: 1px solid #aaa;
  margin-right: 3px;
  margin-left: 3px;
  transition: 0.3s all;
  cursor: pointer;
}

.break-selector > div:hover,
.session-selector > div:hover {
  background-color: rgba(255,255,255,0.06);
  transition: 0.3s all;
}

.timer {
  margin: 80px auto;
  text-align: center;
  border: 20px solid #af0;
  height: 400px;
  width: 400px;
  border-radius: 50%;
  line-height: 180px;
  cursor: pointer;
  transition: 0.3s all;
}

.breakTime .timer {
  border: 10px solid red;
}

.timer:hover {
  background-color: rgba(255,255,255,0.03);
  transition: 0.3s all;
}

.timer h2 {
  margin-top: 50px;
  font-shadow: 3px 3px 5px rgba(0,0,0,0.5);
}

.count-timer {
  font-size: 120px;
}

.no-select {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.breakTime .timer h2 {
  color: #f00;
}

            
          
!
            
              // Global variables
var running = isBreak = false;
var sessionTime = $('.count-timer').data('time');
var sessionSeconds = $('.count-timer').data('seconds');
var breakTime = $('.break-value').data('time');
var breakSeconds = $('.break-value').data('seconds');
// var ping = new Audio("http://cd.textfiles.com/10000soundssongs/WAV/AAHHHHHH.WAV");

// Function to add to break
var addToBreak = function() {
  stopSession();
  var n = $('.break-value').data('time') + 1;
  $('.break-value').data('time', n);
  $('.break-value').data('seconds', n * 60);
  $('.break-value').text(n);
  breakTime = n;
  breakSeconds = n * 60;
};

// Function to subtract from break
var subtractFromBreak = function() {
  stopSession();
  if ($('.break-value').data('time') > 1) {
    var n = $('.break-value').data('time') - 1;
    $('.break-value').data('time', n);
    $('.break-value').data('seconds', n * 60);
    $('.break-value').text(n);
    breakTime = n;
    breakSeconds = n * 60;
  }
};

// Function to add to session
var addToSession = function() {
  stopSession();
  disableBreak();
  var n = $('.session-value').data('time') + 1;
  $('.session-value, .count-timer').data('time', n);
  $('.session-value').data('seconds', n * 60);
  $('.session-value, .count-timer').text(n);
  sessionTime = n;
  sessionSeconds = n * 60;
};

// Function to subtract from session
var subtractFromSession = function() {
  stopSession();
  disableBreak();
  if ($('.session-value').data('time') > 1) {
    var n = $('.session-value').data('time') - 1;
    $('.session-value, .count-timer').data('time', n);
    $('.session-value, .count-timer').data('seconds', n * 60);
    $('.session-value, .count-timer').text(n);
    sessionTime = n;
    sessionSeconds = n * 60;
  }
};

// Function to stop session
var stopSession = function() {
  running = false;
  isBreak = false;
};

// Function to start session
var startSession = function() {
  running = true;
};

// Clock function (1000ms = 1s)
setInterval(function() {
  if (running == true) {
    countDown();
    breakDown();
  }
}, 1000);

// Function to count down session
var countDown = function() {
  if (isBreak == false) {
    sessionSeconds = sessionSeconds - 1; // Counts down by one second
    var displayTime = Math.floor(sessionSeconds / 60); // Gets minutes from total seconds
    var displaySeconds = sessionSeconds - displayTime * 60; // Gets remaining seconds from total seconds
    if (displaySeconds > 9) {
      $('.count-timer').text(displayTime + ":" + displaySeconds);
    } else {
      $('.count-timer').text(displayTime + ":0" + displaySeconds);
    }
    if (sessionSeconds == 0) {
      isBreak = true;
      breakSeconds = $('.break-value').data('seconds');
      $('.timer h2').text('Break');
      $('body').addClass('breakTime');
      // ping.play();
    }
  }
};

var disableBreak = function () {
  isBreak = false;
  sessionSeconds = $('.session-value').data('seconds');
  $('.timer h2').text('Session');
  $('body').removeClass('breakTime');
};

// Function to count down break
var breakDown = function() {
  if (isBreak == true) {
    breakSeconds = breakSeconds - 1; // Counts down by one second
    var displayTime = Math.floor(breakSeconds / 60); // Gets minutes from total seconds
    var displaySeconds = breakSeconds - displayTime * 60; // Gets remaining seconds from total seconds
    if (displaySeconds > 9) {
      $('.count-timer').text(displayTime + ":" + displaySeconds);
    } else {
      $('.count-timer').text(displayTime + ":0" + displaySeconds);
    }
    if (breakSeconds == 0) {
      disableBreak();
    }
  }
};

// Control function
$('.timer').on('click', function() {
  if (running == true) {
    stopSession();
  } else {
    startSession();
  }
});
            
          
!
999px
Loading ..................

Console