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 includes JSX processing.

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

Packages

Add Packages

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.

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

              
                <div class="wrapper">
  <div class="wrapper-inner container">
    
    <div class="progress">
      <div class="determinate" id="progress-bar"></div>
    </div> <!-- progress bar -->
    
    <div class="pomodoro">
      <div class="pomodoro__top">
        <div class="pomodoro__top_curent_state">
          <span class="pomodoro__top_current_state__title">CURRENT STATE</span> <!-- current state title -->
          <span class="pomodoro__top_current_state__text" id="current-state">WORK</span>
        </div>  <!-- pomodoro current state -->
        <div class="pomodoro__top_buttons row">
          <div class="pomodoro__top_buttons_left col s12 m6">
            <div class="pomodoro__top-buttons_left__title">
              BREAK
            </div>
            <i class="material-icons" id="sub-break">remove</i>
            <span id="break-time">5m</span>
            <i class="material-icons" id="add-break">add</i>
          </div>  <!-- pomodoro button left -->
          <div class="pomodoro__top_buttons_right col s12 m6">
            <div class="pomodoro__top-buttons_left__title">
              SESSION
            </div>
            <i class="material-icons" id="sub-session">remove</i>
            <span id="session-time">25m</span>
            <i class="material-icons" id="add-session">add</i>
          </div>  <!-- pomodoro button right -->
        </div> <!-- pomodoro top buttons  -->
      </div> <!-- pomodoro top-->
      <div class="pomodoro__middle">
        <div class="pomodoro__middle_wrapper" id="border-wrapper">
          <div class="pomodoro__middle_wrapper__inner" id="clock">
            <span>25m</span>
          </div>
        </div>
      </div> <!-- pomodoro middle-->
      <div class="pomodoro__bottom">
        <div class="pomodoro__bottom-button">
          <a class="waves-effect waves-light btn-large" id="start-stop">START</a>
        </div> <!-- pomodoro bottom button -->
      </div> <!-- pomodoro bottom row-->
    </div> <!-- pomodoro -->
    
  </div>  <!-- wrapper-inner container -->
</div> <!-- wrapper -->

        
              
            
!

CSS

              
                //variables and mixins
$primary-color: #432F74;
$secondary-color: #8778AD;
$accent-color: #B5AACF;


body{
  width: 100%;
  height: 100%;
  background: #635091;
}

.wrapper {
  height: 100%;
  &-inner{
    height: 100%;
  }
}

.progress{
  margin-top: 20px;
}

.pomodoro{
  text-align: center;
  color: white;
  
  //top
  &__top{
    //state
    &_current_state{
      //title
      &__title{
        display: block;
        font-size: 1em;
        color: $accent-color;
      }
      //text
      &__text{
        font-size: 2em;
        
      }
    }
    
    //buttons
    &_buttons{
      margin-top: 50px;
      //left and right
      &_left, &_right{
        //titles
        &__title{
          
        }
        //the icons
        i{
          cursor: pointer;
          
          &:hover{
            color: $secondary-color;
          }
          &:active{
            color: $accent-color;
          }
        }
        //the spans
        span{
          padding: 0 10px;
          font-size: 2em;
        }
      }
      
      //add margin top to the session span below 600px
      &_right{
        @media only screen and (max-width: 601px){
          margin-top: 20px;
        }
      }
      
    }
    
  }
  
  //middle
  &__middle{
    margin-top: 50px;
    //wrapper
    &_wrapper{
      display: inline-block;
      border-radius: 50%;
      border: 3px solid $primary-color;
      height: 200px;
      width: 200px;
      
      //inner flex container
      &__inner{
        display: flex;
        height: 100%;
        flex-flow: row nowrap;
        align-items: center;
        justify-content: center;
        
        //the timer spans
        span{
          padding: 0 3px;
          font-size: 2em;
        }
      }
    }
  }
  
  //bottom
  &__bottom{
    margin: 50px 0 20px 0;
  }
}
              
            
!

JS

              
                

//variables colors. Constants
const primaryColor = "#26a69a";
const secondaryColor = "#ffeb3b";
const stopColor = "#e53935";

//variables times
let sessionTime = 25;
let breakTime = 5;
let currentTime = 25;

//clock state
var clockState = "off";

//session and break functions
var runSession, runBreak;

//timer interval
var timer;

//let's begin
$(function(){  
  //first capture the buttons and spans
  //progress bar
  let pBar = $("#progress-bar");
  let pBarParent = pBar.parent();
  //current state
  let currentState = $("#current-state");
  //break
  let subBreak = $("#sub-break");
  let breakValue = $("#break-time");
  let addBreak = $("#add-break");
  //session
  let subSession = $("#sub-session");
  let sessionValue = $("#session-time");
  let addSession = $("#add-session");
  //clock
  let clock = $("#clock");
  let borderWrapper = $("#border-wrapper");
  //start/stop
  let startStop = $("#start-stop");
  
  //functions to execute break actions
  let subtractBreak = function(){ 
    if(breakTime > 1){
      breakTime--;
      updateDisplay(breakTime, "break");
    }
    else{
      toast("Can't have a break shorter than a minute.", 3000);
    }
  };
  let addToBreak = function(){
    breakTime++;
    updateDisplay(breakTime, "break");
  };
  //subtract from break
  subBreak.click(subtractBreak);
  //add to break
  addBreak.click(addToBreak);

  
  //functions to execute session actions
  let subtractSession = function(){
    if(sessionTime > 5){
      sessionTime--;
      updateDisplay(sessionTime, "session");
    }
    else{
      toast("Less than 5 minutes, seriously? Nah.", 4000);
    }
  };
  let addToSession = function(){
    sessionTime++;
    updateDisplay(sessionTime, "session");
  };
  //subtract from session
  subSession.click(subtractSession);
  addSession.click(addToSession);
  
  //run session function
  runSession = function(){
    currentState.text("WORK");
    //change colors to break
    pBarParent.css("background-color", "#acece6");
    pBar.css("background-color", primaryColor);
    borderWrapper.css("border-color", primaryColor);
    
    
    let _sessionTime = sessionTime;
    let hours = Math.floor(_sessionTime/60);
    let minutes = (_sessionTime % 60);
    let seconds = 00;
    
    updateClock(clock, hours, minutes, seconds);
    //countdown function
    countDown(clock, hours, minutes);   
    //progressBar
    runPBar(_sessionTime*60);
  };
  //run break function
  runBreak = function(){
    currentState.text("BREAK");
    //change colors to break
    pBarParent.css("background-color", "#fffde7");
    pBar.css("background-color", secondaryColor);
    borderWrapper.css("border-color", secondaryColor);
    
    
    let _breakTime = breakTime;
    let hours = Math.floor(_breakTime/60);
    let minutes = (_breakTime % 60);
    let seconds = 00;
    
    updateClock(clock, hours, minutes, seconds);
    //countdown function
    countDown(clock, hours, minutes);
    //progressBar
    runPBar(_breakTime*60);
  }
  
  
  //the start stop functions
  startStop.click(function(){
    let button = $(this);
    if(clockState === "off"){
      //start
      button.css("background-color", stopColor);
      button.text("STOP");
      runSession();
      clockState = "session";
    }
    else{
      //stop it
      clockState = "off";
      button.css("background-color", primaryColor);
      button.text("START");
      pBar.finish();
    }
  });
  
  //progress bar function
  var runPBar = function(seconds){
    const initialSeconds = seconds*1000;
    pBar.animate({width: "100%"}, initialSeconds, "linear", function(){
      pBar.width(0);
    }); 
  }
  

});
  
//toast function
function toast(message, duration){
  var duration = duration;
  if(arguments.length === 1){
    duration = 2000;
  }
  Materialize.toast(message, duration);
}

//update break and session spans
function updateDisplay(withWhat, whichOne){
  if(whichOne === "break"){
    $("#break-time").html(withWhat + "m");
  }
  else if(whichOne === "session"){
    $("#session-time").html(withWhat + "m");
  }
}

//function to update clock
function updateClock(clock, hours, minutes, seconds){
    let html;
    if (hours > 0){
      html = `<span>${hours}h</span>
              <span>${minutes}m</span>
              <span>${seconds}s</span>`;
    }
    else if(minutes > 0){
      html = `<span>${minutes}m</span>
              <span>${seconds}s</span>`;
    }
  else{
    html = `<span>${seconds}s</span>`;
  }
    clock.html(html);
}

//function to countdown
function countDown(clock, hours, minutes){
  let seconds = 60;
  //sorting out that weird bug at 60 minutes
  if(minutes === 0 && hours > 0){
    var hours = hours - 1;
    minutes = 59;
  }
  else{
    var minutes = minutes -1;
  }
  
  var timer = setInterval(function(){
    if(clockState != "off"){
      if(hours > 0 || minutes > 0 || seconds > 0){
        if(seconds > 0){
          seconds--;
          updateClock(clock, hours, minutes, seconds);
        }
        else{
          if(minutes > 0){
            minutes--;
            updateClock(clock, hours, minutes, seconds);
            seconds = 59;
          }
          else{
            hours--;
            updateClock(clock, hours, minutes, seconds);
            minutes = 59;
          }

        }
      }
      else{
        clearInterval(timer);
        if(clockState === "session"){
          runBreak();
          clockState = "break";
        }
        else if(clockState === "break"){
          runSession();
          clockState = "session";
        }
      }
    }
    else{
      clearInterval(timer);
    }
    
  }, 1000);
}
  
              
            
!
999px

Console