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.

            
                    <div id="countdown">
	<span id="timer">25:00</span>
      </div>
      <button id="reset">Reset</button>
      <div id="session">
	<p>Session Length</p>
	<button class="changeVal">-</button><span id="sessVal">25</span><button class="changeVal">+</button>
      </div>
      <div id="break">
	<p>Break Length</p>
	<button class="changeVal">-</button><span id="breakVal">5</span><button class="changeVal">+</button>
      </div>      
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Roboto');

html, body {
    margin: 0;
    padding: 0;
    width: 100%;

    color: #444;

    font-family: 'Roboto', sans-serif;
}

body {
    background-color: #c95757;
}

button {
    background-color: #c95757;
    border: none;
}

#countdown {
    background-color: #ffb9b9;
    color: #444;    

    height: 180px;
    width: 180px;

    border-radius: 180px;

    line-height: 180px;
    text-align: center;
    font-size: 48px;

    margin: 90px auto 0 auto;
}

#reset {
    color: #eee;
    font-size: 24px;

    margin: 10px auto 0 auto;
    display: block;
    text-align: center;
}

#countdown:hover, #reset:hover, .changeVal:hover {
    cursor: pointer;
    cursor: hand;
}

#session, #break {
    margin: 10px auto 0 auto;
    color: #eee;
    font-size: 20px;

    text-align: center;
}

#sessVal, #breakVal {
    font-size: 24px;
    margin: 0 10px 0 10px;
}

.changeVal {
    color: #eee;
    font-size: 24px;
}
            
          
!
            
              $(document).ready(function() {

    // session duration
    var sessDur = 25;
    // break duration
    var breakDur = 5;
    
    $("#session .changeVal").click(function() {
	if (clockState === "active")
	{
	    clockState === "idle";
	    clearInterval(clock);
	}
	
	if ($(this).text() === '-')
	    sessDur--;
	else if ($(this).text() === '+')
	    sessDur++;

	$("#sessVal").html(sessDur);
	$("#timer").html(sessDur + ":00");
    });
    
    $("#break .changeVal").click(function() {
	if ($(this).text() === '-')
	    breakDur--;
	else if ($(this).text() === '+')
	    breakDur++;
	$("#breakVal").html(breakDur);
    });

    var clock;
    
    // clockState used in manipulating the clock
    var clockState = "idle";

    // used to determine if using session timer or break timer
    var currClock = "session";

    var seconds = 60;
    var minutes;    
    
    $("#countdown").click(function() {

	if (currClock === "session")
	    minutes = sessDur;
	else if (currClock === "break")
	    minutes = breakDur;


	if (clockState === "idle" || clockState === "paused")
	{

	    clock = setInterval(function() {

		if (clockState === "idle")
		    minutes--;
		
		clockState = "active";
		

		if (seconds > 0)
		{
		    --seconds;
		    if (seconds > 9)
			$("#timer").html(minutes + ":" + seconds);
		    else
			$("#timer").html(minutes + ":0" + seconds);
		}
		else if (seconds === 0)
		{
		    if (minutes === 0)
		    {
			if (currClock === "session")
			{
			    minutes = breakDur;
			    currClock = "break";
			}
			else if (currClock === "break")
			{
			    minutes = sessDur;
			    currClock = "session";
			}
			
			seconds = 60;

			clockState = "idle";
		    }
		    else
		    {
			--minutes;
			
			if (currClock === "session")
			    sessDur = minutes;

			else if (currClock === "break")
			    breakDur = minutes;

			seconds = 60;
		    }
		}
		
	    }, 1000);
	}
	else if (clockState === "active")
	{
	    clockState = "paused";
	    clearInterval(clock);
	}

    });

    $("#reset").click(reset);

    function reset() {
	if (clockState === "active")
	    clearInterval(clock);
	
	sessDur = 25;
	breakDur = 5;
	seconds = 60;
	
	$("#timer").html(sessDur + ":00");
	$("#sessVal").html(sessDur);
	$("#breakVal").html(breakDur);

	currClock = "session";
	clock = undefined;
	clockState = "idle";
    }

});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console