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.

            
              <html>
<head>
	<title>Pomodoro Clock</title>
</head>
<body>
	<div class="centered-block">
		<h2>Pomodoro Timer</h2>
		<div class="row">
			<div class="col-xs-3"></div>
			<div class="col-xs-3">
				Work Time
				<div class="row">
					<div class="col-xs-4">
						<div id="plusWork" class="btn btn-default">+</div>
					</div>
					<div id="workTime" class="col-xs-4 big fcc-background">
						25
					</div>
					<div class="col-xs-4">
						<div id="lessWork" class="btn btn-default">-</div>
					</div>
				</div>

			</div>
			<div class="col-xs-3">
				Rest Time
				<div class="row">
					<div class="col-xs-4">
						<div id="plusRest" class="btn btn-default">+</div>
					</div>
					<div id="restTime" class="col-xs-4 big fcc-background">
						5
					</div>
					<div class="col-xs-4">
						<div id="lessRest" class="btn btn-default">-</div>
					</div>
				</div>
			</div>
		</div>
		<svg width="250" height="250" >
  			<defs>
    			<pattern id="image" patternUnits="userSpaceOnUse" height="250" width="250">
      			<image x="0" y="0" height="250" width="250" xlink:href="http://edgarsh.es/wp-content/uploads/2016/05/fcc-app-icon.png"></image>
    			</pattern>
  			</defs>
 			<circle id='top' cx="125" cy="125" r="125" fill="url(#image)"/>
  
  			<path id="loader" transform="translate(125, 125)"/>
		</svg>
		<div id="announcment">READY TO WORK</div>
		<div id="timer" class="big button"></div>
		<button id="start">start</button>
		<button id="stop">stop</button>
		<button id="reset">reset</button>
	</div>

</body>
</body>
</body>
</html>
            
          
!
            
              body {
	background-color: #457E86 !important;
}

.centered-block {
	margin-top: 30px;
	text-align: center;
	background-image: url(http://edgarsh.es/wp-content/uploads/2016/05/freeCodeCamp-socialBanner.png);
	background-repeat: no-repeat;
	background-size: cover;
	padding-bottom: 30px;
	font-family: monospace;
	border:10px solid #4A2B0F;
	
}

h2 {
	color: #EEEEEE;
	padding-top: 30px;
  text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
	
}

.big {
	font-size: 2em;
}

.button {
	cursor: pointer;
}

svg {
  display: block;
  margin: 50px auto;
}

#loader { 
	fill: red;
  opacity: 0.3;	}

.fcc-background {
	background-color: #4A2B0F;
	color: white;
	border-radius: 15px;
}


            
          
!
            
              $(document).ready(function(){

	timer.setTimer(); //For getting the timer ready
                    //when the page is loaded

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

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

	$('#reset').click(function(){
		timer.setTimer();
		$('#timer').text(timer.getTime());
	});

	$('#plusWork').click(function(){
		modifyNumber("#workTime", +1);
		timer.setTimer();
	});

	$('#plusRest').click(function(){
		modifyNumber("#restTime", +1);
    timer.setTimer();
	});

	$('#lessWork').click(function(){
		modifyNumber("#workTime", -1);
		timer.setTimer();
	});

	$('#lessRest').click(function(){
		modifyNumber("#restTime", -1);
    timer.setTimer();
	});

});

function modifyNumber(numberId, modifier){
	var current = parseInt($(numberId).text(), 10);
  if(current + modifier >= 0){
    $(numberId).text(current + modifier);
  }
}

function getUserTime(timerId){
	//gets the time in minutes and returns it as seconds
	return parseInt($(timerId).text(), 10) * 60;
}

var timer = {
	totalSeconds: null,
	runningTime: null,
	
	timeHandler: null,	//handler which will run the setInterval function
	svgHandler: null,	//handler for the svg animation

	isWorkTime: true,	//For knowing if we must run the work timer or
						//the rest timer

	getTime: function(){
		function formating(value){
			value = value.toString();
			if(value.length < 2){
				return '0' + value;
			} else {
				return value;
			}
		}
		var minutes = Math.floor(this.runningTime / 60);
		var totalSeconds = this.runningTime - (minutes * 60);
		return formating(minutes) + " : " + formating(totalSeconds);
	},
	resetTime: function(){
		this.setTimer();
	},
	startTimer: function(){
		var that = this; //allows to refer to the timer object
		this.timeHandler = setInterval(function(){
			
			if(that.runningTime > 0){
				that.runningTime--;
			} else{
				that.stopTimer();

				that.isWorkTime = !that.isWorkTime;	//changes the bool value of
													//the variable when the timer
													//is out of time

				that.setTimer();
			}
			$('#timer').text(that.getTime());
			that.svgHandler(that.totalSeconds - that.runningTime);
		}, 1000);
	},
	stopTimer: function(){
		clearInterval(this.timeHandler);
	},
	setTimer: function(){
		var color; //color for the svg animation
		var timerId;
		var timerMessage;
    this.stopTimer();
		if(this.isWorkTime){
			color = "red";
			timerId = "#workTime";
			timerMessage = "WORK TIME!!";
		} else {
			color = "green";
			timerId = "#restTime";
			timerMessage = "REST TIME!!";
		}

		var seconds = parseInt($(timerId).text(), 10) * 60;
		this.totalSeconds = seconds;
		this.runningTime = seconds;

		$('#announcment').text(timerMessage);
		this.svgHandler = animationHandler(seconds, color);
		this.svgHandler(this.totalSeconds - this.runningTime);
		$('#timer').text(this.getTime());
	},

	getIsWorkTime: function(){
		return this.isWorkTime;
	}
};


//Credits for Andreu Grimsrud who build a SVG pie
//timer which was the foundation for this animation
//https://codepen.io/agrimsrud/pen/EmCoa/

function animationHandler(seconds, color){
  var loader = document.getElementById("loader");
  var alpha = 0;
  var pi = Math.PI;
  var t = 30;
  var totalTimePeriod = seconds;
  $('#loader').css("fill", color);
  
  function draw(secs) {
    alpha = 360 * (secs/totalTimePeriod);
    var r = ( alpha * pi / 180 );
    var x = Math.sin( r ) * 125;
    var y = Math.cos( r ) * - 125;
    var mid = ( alpha > 180 ) ? 1 : 0;
    var anim = 'M 0 0 v -125 A 125 125 1 ' +
            mid + ' 1 ' +
             x  + ' ' +
             y  + ' z';
   
    loader.setAttribute( 'd', anim );
  }

  return draw;
}

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

Console