Pen Settings

HTML

CSS

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.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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.

+ add another resource

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Pomodoro Timer</h1>

<div id="app"></div>
              
            
!

CSS

              
                /**
 * Add box sizing to everything
 * @link http://www.paulirish.com/2012/box-sizing-border-box-ftw/
 */
*,
*:before,
*:after {
	box-sizing: border-box;
}

/**
 * Layout
 */
body {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
	font-size: 112.5%;
	margin-left: auto;
	margin-right: auto;
	max-width: 40em;
	width: 88%;
}

/**
 * Style the timer
 */
#timer {
	font-size: 2em;
	font-weight: bold;
}
              
            
!

JS

              
                //
// Variables
//

var countdown;


//
// Methods
//

/**
 * Play an alarm sound
 */
var alarm = function () {
    var alarm = new Audio('https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/Yodel_Sound_Effect.mp3');
    alarm.play();
};

/**
 * Add a leading 0 if none exists
 * @param  {Integer} num The number to pad
 * @return {String}      The padded number
 */
var padLeft = function (num) {
    if (num.toString().length < 2) {
        return '0' + num;
    }
    return num;
};

/**
 * Reset the timer
 */
var reset = function () {
    timer.setData({time: 1500});
};

var tick = function () {

    // Update the timer
    timer.setData({
        time: timer.getData().time - 1,
        running: true
    });

    // If the timer reaches zero, stop and sound an alarm
    if (timer.getData().time === 0) {
        stop();
        alarm();
    }

};

/**
 * Start the timer
 */
var start = function () {

    // If the timer is at 0, reset it
    if (timer.data.time === 0) {
        reset();
    }

    // Start the timer
    tick();

    // Update the timer once a second
    countdown = window.setInterval(tick, 1000);

};

/**
 * Stop the timer
 */
var stop = function () {
    window.clearInterval(countdown);
    timer.setData({running: false});
};

/**
 * Handle click events
 */
var clickHandler = function (event) {

    // Check if a timer action button was clicked
    var action = event.target.getAttribute('data-action');
    if (!action) return;

    // If it's the start button, start the timer
    if (action === 'start') {
        start();
        return;
    }

    // If it's the stop button, stop the timer
    if (action === 'stop') {
        stop();
        return;
    }

    // If it's the clear button, reset
    if (action === 'clear') {
        stop();
        reset();
    }

};


//
// Inits & Event Listeners
//

// Create the timer
var timer = new Reef('#app', {
    data: {
        time: 1500,
        running: false
    },
    template: function (props) {
        var html =
            '<div id="timer">' +
                parseInt(props.time / 60, 10).toString() + ':' + padLeft(props.time % 60) +
            '</div>' +
            '<p>' +
                '<button data-action="' + (props.running ? 'stop' : 'start') + '">' + (props.running ? 'Pause' : 'Start') + '</button>' +
                '<button data-action="clear">Reset</button>' +
            '</p>';
        return html;
    }
});

// Render the timer into the DOM
timer.render();

// Listen for clicks
document.addEventListener('click', clickHandler, false);
              
            
!
999px

Console