css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Pomodoro Clock</title>
    <script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,600,700" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Courgette" rel="stylesheet">
    <link rel="stylesheet" href="./assets/main.css">
</head>
<body>
    <div id="title">
        <h1>My Pomodoro Clock</h1>
    </div>

    <div class="box">
        <div id="setting-container">
            <div class="setting-title">Settings</div>
            <div class="setting-length">
                <span class="length-title">Session</span>
                <div class="button pointer" onClick="changeVal('session-value','-')">-</div>  
                <div id="session-value" class="set-value">25</div>
                <div class="button pointer" onClick="changeVal('session-value', '+')">+</div>
            </div>
            <div class="setting-length">
                <span class="length-title">Break</span>
                <div class="button pointer" onClick="changeVal('break-value','-')">-</div>  
                <span id="break-value" class="set-value">5</span>
                <div class="button pointer" onClick="changeVal('break-value','+')">+</div>  
            </div>
            <div class="setting-length">
                <span class="length-title">Long break</span>
                <div class="button pointer" onClick="changeVal('break-lg-value','-')">-</div>  
                <span id="break-lg-value" class="set-value">15</span>
                <div class="button pointer" onClick="changeVal('break-lg-value','+')">+</div>  
            </div>
            <div class="btn-start pointer" onClick="switchPane()">
                <p>Click to start</p>
                <i class="fas fa-clock fa-4x"></i>
            </div>
        </div>
        <div id="timer-container">
            <div id="timer-section">
                <div id="progress" class="session">
                    <div class="back-settings">
                        <i class="fas fa-cogs pointer" onClick="switchPane()"></i>
                        <div class="pointer" onClick="reset()">reset</div>
                        <div id="currTimer">Working</div>
                    </div>
                    <div class="container">
                        <span id="timer-val-min">25</span>
                        <span id="timer-val-sec">00</span>
                    </div>
                </div>
            </div>
            <div class="btn-play pointer" onClick="toggleTimer()">
                <div id="play"><i class="fas fa-play fa-2x"></i></div>
                <div id="pause"><i class="fas fa-pause fa-2x"></i></div>
            </div>
        </div>
    </div>
    <div id="footer">
        <p>Coded with lots of <i class="fa fa-coffee"></i> by Fabien Shan, 2018</p>
        <p>Inspired by <a href="https://dribbble.com/shots/2927583-Pomodoro-timer">Bram Schulting's pomodoro timer</a></p>
    </div>

</body>
<script src="./assets/script.js"></script>
</html>
            
          
!
            
              /* =====================
    General style
======================*/

body {
    background-color: #DBEBFF;
}

.box {
    width: 500px;
    border: 1px solid black;
    margin: auto;
    background-color: rgba(0,0,0,0.2);
    font-family: 'Open Sans', sans-serif;
}

.pointer {
    cursor: pointer;
}

/* =====================
        Title
======================*/
#title {
    width: 500px;
    margin: auto;
    text-align: center;
    font-family: 'Courgette', cursive;
}


/* =====================
    Setting container
======================*/

#setting-container {
    width: 85%;
    position: relative;
    top: 15%;
    left: 8%;
    margin: 30px 0;
    display: grid;
    grid-template-rows: 2fr repeat(3, 1fr);
    grid-template-columns: repeat(2,1fr);
    grid-row-gap: 12px;
    justify-items: stretch;
}

.setting-title {
    grid-column: 1/2;
    font-size: 1.5em;
    font-weight: 700;
}

.setting-length {
    grid-column: 1/2;
    display: flex;
    justify-content: center;
}

.length-title {
    flex-grow: 1; /* Allow the title to take the whole left space */
}

.button {
    width: 15px;
    text-align: center;
    vertical-align: middle;
    font-weight: bold;
}

.set-value {
    width: 30px;
    text-align: center;
}

.timer {
    background-color:#baffc9;
}

.btn-start {
    font-weight: 600;
    grid-column: 2/3;
    grid-row: 1/5;
    justify-self: end;
    align-self: center;
    text-align: center;
}

/* =====================
    Timer container
======================*/

#timer-container {
    height: 100px;
    display: none;
    justify-content: space-between;
    align-items: flex-end;
}

#timer-section {
    height: 100%;
    display: flex;
    flex-grow: 1;
    color: #0D2625;
}

.back-settings {
    width: 170px;
    margin: 10px 0 0 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
}

#currTimer {
    color: #673567;
}

#timer-container .container {
    width: 100px;
    margin: 0 0 7px 15px;
}

#timer-val-min {
    font-size: 2em;
}

#timer-val-sec {
    position: relative;
    top: 3px;
    vertical-align: top;
    font-size: 1.2em; 
}

.btn-play {
    height: 100%;
    margin-top: 5px;
    width: 80px;
    text-align: center;
    background-color: rgba(0, 0, 0, 0.3);   
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
}

#pause {
    display: none;
}

/* progress bar */
#progress {
    height: 100%;
    width: 0%;
    display: flex;
    justify-content: space-between;
    flex-direction: column;
}

.session {
    background: linear-gradient(to bottom, #e27a7c 0%,#d1272a 40%,#991e20 100%);
}

.break {
    background: linear-gradient(to bottom, #7db9e8 0%,#2989d8 40%,#2775c4 100%);
}

.break-lg {
    background: linear-gradient(to bottom, #28d628 0%,#28d628 40%,#1e991e 100%);
}

/* =====================
       Footer style
======================*/

#footer {
    width: 500px;
    margin: 25px auto;
    text-align: center;
    font-size: 0.8em;
    line-height: 0.2em;
}
            
          
!
            
              // set switch variables
var isRunning = false;
var nextBreak = false;
var sessionCount = 0;
// secInterval needs to be declared outside the function toggleTimer 
// otherwise will create a new var for every click and won't be able
// to properly clearInterval on it
var secInterval;
var currId = 'session-value';  // defines current displayed value so that changes in settings do not reset timer
var timerVal = document.getElementById(currId).innerHTML;
// global element selector
var min = document.getElementById('timer-val-min');
var sec = document.getElementById('timer-val-sec');

function changeVal(id, type) {
    var display = document.getElementById(id);
    var currVal = parseInt(display.innerHTML);

    if (type === '-' && currVal > 1) {
        currVal -= 1;
    } else if (type == '+') {
        currVal += 1;
    }
    
    // change displayed value
    display.innerHTML = currVal;

    // change the value of the session length
    if (id === 'session-value' && currId === 'session-value') {
        document.getElementById('timer-val-min').innerHTML = currVal;
        document.getElementById('timer-val-sec').innerHTML = '00';
        timerVal = currVal;
    }
}

function toggleTimer() {
    nextBreak = !nextBreak;

    if (isRunning) {
        isRunning = !isRunning;     // toggle running status
        // Toggle which icon is shown on the play section
        toggleDisplay('play', 'block');
        toggleDisplay('pause', 'none');
        clearInterval(secInterval);
    } else {
        isRunning = !isRunning;     // toggle running status
        // Toggle which icon is shown on the play section
        toggleDisplay('play', 'none');
        toggleDisplay('pause', 'block');

        // Timer function
        secInterval = setInterval(function() {
            // Get the current value of seconds
            var secVal = sec.innerHTML;
            // change color of progress bar
            document.getElementById('progress').className = currId.substr(0, currId.length - 6);
            // Decrement logics
            if (secVal === "00") {
                // seconds display 0
                var minVal = min.innerHTML;
                if (minVal === "00") {
                    // minutes display 0
                    // Stop the clock
                    clearInterval(secInterval);
                    // Switch the value of id 
                    var str;
                    if (nextBreak) {
                        if (sessionCount % 4 === 0 && sessionCount > 1) {
                            currId = 'break-lg-value';
                            str = 'Long break';
                        } else {                    
                            currId = 'break-value';
                            str = 'Break';
                        }
                    } else {
                        currId = 'session-value';
                        sessionCount += 1;
                        str = 'Working';
                    }
                    // reset variables
                    isRunning = !isRunning;
                    timerVal = document.getElementById(currId).innerHTML;
                    document.getElementById('currTimer').innerHTML = str;
                    // Change the displayed value of minutes
                    min.innerHTML = ('0' + timerVal).slice(-2);
                    // restart the clock with the break or session
                    toggleTimer();
                } else {
                    // Decrease and display the minutes
                    minVal -= 1;
                    min.innerHTML = ('0' + minVal).slice(-2);
                    sec.innerHTML = 59;                                 // Reset seconds
                }
            } else {                                                    // Decrease the seconds
                secVal -= 1;
                sec.innerHTML = ('0' + secVal).slice(-2);
            }

            // calculate remaining time
            var remaining = min.innerHTML * 60 + parseInt(sec.innerHTML); 
            // calculate maxtime
            var maxtime = timerVal * 60;
            // manipulate width to show timer progress
            timerFiller(remaining, maxtime);
        }, 1000);
    }
}

function switchPane() {
    // Switch between settings and timer panel
    if (document.getElementById('setting-container').style.display === 'none') {
        toggleDisplay('setting-container', 'grid');
        toggleDisplay('timer-container', 'none');
    } else {
        toggleDisplay('setting-container', 'none');
        toggleDisplay('timer-container', 'flex');
    }

    if (isRunning) {
        toggleTimer();
    }
}

function toggleDisplay (id, displayValue) {
    document.getElementById(id).style.display = displayValue;
}

function timerFiller(remaining, maxtime) {
    var progressPerc = Math.round((maxtime - remaining) / maxtime * 100 * 100) / 100;
    document.getElementById('progress').style.width = progressPerc + '%';
}

function reset() {
    // stop the timer if
    if(isRunning) {
        isRunning = !isRunning;
        clearInterval(secInterval);
    }
    nextBreak = false;
    sessionCount = 0;

    currId = 'session-value';
    timerVal = document.getElementById(currId).innerHTML;
    min.innerHTML = timerVal;
    sec.innerHTML = '00';
    document.getElementById('progress').style.width = '0%';

    // restart the timer
    toggleTimer();
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console