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.

            
              <div class="container-fluid">
  <div class="hidden alert alert-success alert-dismissible fade in" id="breakAlert" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
    <strong>Break time!</strong> Take five.
  </div>
  <div class="hidden alert alert-warning alert-dismissible fade in" role="alert" id="workAlert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
    <strong>Back to work!</strong> You can do this.
  </div>
  <div class="row top text-center">
    <button class="btn btn-danger" id="stopClock">Stop</button>
    <button class="btn btn-success" id="startClock">Start</button>
  </div>
  <div class="row">
    <div class="jumbotron col-xs-6 col-xs-offset-3 col-md-4 col-md-offset-4 timer">
      <h1 class="text-center" id="timer"></h1>
    </div>
  </div>
  <div class="row text-center">
    <div class="btn-group toggle" data-toggle="buttons" role="button">
      <button type="button" class="btn btn-default btn-primary" id="work-mode">Work</button>
      <button type="button" class="btn btn-default" id="break-mode">Break</button>
    </div>
  </div>
  <div class="row text-center">
    <button class="btn btn-danger" id="decreaseTime">-</button>
    <button class="btn btn-default" id="reset">Reset</button>
    <button class="btn btn-success" id="increaseTime">+</button>
  </div>
<div id="push"></div>
</div>
<div class="container-fluid">
  <div class="text-center" id="footer">
    <p class="muted credit">&copy <a href="https://codepen.io/jonfulk/full/eZgXeM/" target="_blank">Jonathan Fulk</a> 2016. All Rights Reserved.</p>
  </div>
</div>
            
          
!
            
              body {
  height: 100%;
  background-image: url("http://gdurl.com/U_HN");
  background-attachment: fixed;
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
}

.btn {
  border: 1px solid black;
-webkit-box-shadow: 0px 2px 30px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 0px 2px 30px rgba(50, 50, 50, 0.75);
box-shadow: 0px 2px 30px rgba(50, 50, 50, 0.75);

}

.top {
  margin-top: 50px;
}

.toggle {
  margin-bottom: 20px;
}

.timer {
  margin-top:  30px;
  padding: 20px;
  border: 1px solid;
  font-family: 'orbitron', sans serif;
}

/* Set the fixed height of the footer here */

#push,
#footer {
  height: 50px;
  color: #000;
  color: white;
}


/* Lastly, apply responsive CSS fixes as necessary */

@media (max-width: 767px) {
  #footer {
    margin-left: -20px;
    margin-right: -20px;
    padding-left: 20px;
    padding-right: 20px;
  }
}
            
          
!
            
              // start things at document ready
$(document).ready(function(){
  // Objects we'll interact with
  var _countdown = null; 
  var alerts = {
    breakAlert: $('#breakAlert'),
    workAlert: $('#workAlert'),
    showAlert: function($el) {
      // Display work/break alerts when timer hits zero
      $el.toggleClass("hidden");
      setTimeout(function() {
        $el.toggleClass("hidden");
        }, 10000);
      }
  };
  
  var timer = {
    // h1 that displays timer state as jQuery object
    display: $('#timer'),
    //vars for work/break switch
    workMode: $('#work-mode'),
    breakMode: $('#break-mode'),
    // work or break time?
    working: true,
    // timer seconds attribute
    secs: 0,
    // timer minutes attribute
    mins: 25,
    audio: new Audio('http://k003.kiwi6.com/hotlink/hj2dfwux8t/metro-doors.mp3'),
    zero: function() {
      // Is timer at 0:00 yet?
      return (this.mins === 0 && this.secs === 0);
    },
    decreaseMins: function() {
      // Decrease timer by 1 minute
      if (this.mins > 0) {
        this.mins -= 1; 
      }
      this.updateDisplay();
    },
    decreaseSecs: function () {
      // Decrease timer by 1 minute
      if (this.secs > 0) {
        // default: decrease seconds by 1 & update display
        this.secs -= 1;
        this.updateDisplay();
      }
      else if (this.mins > 0 && this.secs === 0) {
        // if timer > 0:00, reset secs, decrease mins
        this.secs = 59;
        this.decreaseMins();
      }
    },
    increaseMins: function() {
      // Increase timer by 1 minute
      this.mins += 1;
      this.updateDisplay();
    },
    reset: function() {
      // Reset timer to default state
      this.mins = (this.working) ? 25 : 5;
      this.secs = 0;
      this.updateDisplay();
    },
    switchMode: function() {
      // Switch working mode on/off
      this.working = !this.working;
    },
    toggleButtons: function() {
      if (this.working) {
        this.workMode.click();
      } else {
        this.breakMode.click();
      }
    },
    updateDisplay: function() {
      // Update the timer display with current
      // minutes & seconds
      var secondsString = (this.secs < 10) ? '0' + this.secs : this.secs;
      this.display.html(this.mins + ':' + secondsString);
    }
  };
  
  var countdown = function() {
    // Handle the actual timer countdown control
    if (!timer.zero()) {
		timer.decreaseSecs();
		_countdown = setTimeout(function() {
			countdown();
        }, 1000);  
    }
    else {
      // We've hit 0:00
      // play sound
      timer.audio.play();
      // show alert
      var alertMode = (timer.working) ? alerts.breakAlert : alerts.workAlert;
      alerts.showAlert(alertMode);
      
      // Switch mode
      timer.switchMode();
      // Reset timer based on new mode
      timer.toggleButtons();
      // Restart the countdown
      countdown();
    }
  };
  
  // Capture the click on Stop button
  $('#stopClock').on('click', function() {
    clearTimeout(_countdown);
  });
  
  // Capture the click on Start button
  $('#startClock').on('click', function() {
    countdown();
  });
  
  // Capture the click on Decrease button
  $('#decreaseTime').on('click', function() {
    timer.decreaseMins();
  });
  
  // Capture the click on Increase button
  $('#increaseTime').on('click', function() {
    timer.increaseMins();
  });
  
  // Capture the click on Reset button
  $('#reset').on('click', function() {
    timer.reset();
  });
  
  // Capture the Work Toggle button
  $('#work-mode').on('click', function() {
    timer.working = true;
    timer.workMode.addClass('btn-primary');
    timer.breakMode.removeClass('btn-primary');
    timer.reset();
  });
  
  // Capture the Break Toggle button
  $('#break-mode').on('click', function() {
    timer.working = false;
    timer.breakMode.addClass('btn-primary');
    timer.workMode.removeClass('btn-primary');
    timer.reset();
  });
  
  timer.updateDisplay();
});
            
          
!
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