HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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;
}
Also see: Tab Triggers