Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ 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

Auto Save

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

              
                <!-- Zen Code:
     main>(div.screen>span.text+div.cursor)+div.keypad>(button*9>{$})+(button>{0})+(button>{DEL})
-->

<main>
  <div class="screen">
    <span class="text"></span>
    <div class="cursor"></div>
  </div>
  <div class="keypad">
    <button>1</button>
    <button>2</button>
    <button>3</button>
    <button>4</button>
    <button>5</button>
    <button>6</button>
    <button>7</button>
    <button>8</button>
    <button>9</button>
    <button>0</button>
    <button>DEL</button>
  </div>
</main>
              
            
!

CSS

              
                $backgroundColor: #232325;
$deviceColor: #2C3538;
$screenColor: #004057;
$screenFont: 'VT323';
$buttonColor: #4AC9FF;

body {
  background: radial-gradient(circle, lighten($backgroundColor, 10%), $backgroundColor);
}

main {
  background: linear-gradient(to bottom left, $deviceColor, lighten($deviceColor, 10%), darken($deviceColor, 2%));;
  border: 3px solid darken($deviceColor, 3%);
  border-radius: 12px;
  box-shadow: 3px 7px 4px -2px darken($backgroundColor, 1%);
  height: 240px;
  margin: 50px auto;
  max-width: 180px;
  padding: 20px;
}

.screen {
  background: $screenColor;
  border: 1px solid $buttonColor;
  border-radius: 6px;
  color: $buttonColor;
  font-family: $screenFont, Courier, monospace;
  font-size: 28px;
  height: 40px;
  line-height: 40px;
  overflow: hidden;
  padding: 0 10px;
  position: relative;
  text-shadow: 0 0 8px;
}

.text {
  position: relative;
  left: auto;
}

.cursor {
  animation: blink 2s linear infinite;
  background-color: $buttonColor;
	content: "";
	display: block;
	width: 20px;
	height: 5px;
	position: absolute;
	top: 30px;
  left: 10px;
}

.keypad {
  background: transparent;
  border-radius: 6px;
  display: flex;
  flex-wrap: wrap;
  height: 180px;
  justify-content: flex-end;
  margin-top: 20px;
}

button {
  background: transparent;
  border: 2px solid $buttonColor;
  border-radius: 4px;
  box-shadow: 0 0 8px -1px;
  color: $buttonColor;
  cursor: pointer;
  font-family: $screenFont, Courier, monospace;
  font-size: 20px;
  font-weight: bold;
  margin: 2%;
  text-shadow: 0 0 8px;
  width: 29%;
  
  &:hover {
    background: $buttonColor;
    box-shadow: 0 0 8px -1px $buttonColor;
    color: $deviceColor;
    text-shadow: 0 0 8px $deviceColor;
  }
}

@keyframes blink {
	0%{opacity: 1;}
	50%{opacity: 1;}
  51%{opacity: 0;}
  100%{opacity: 0;}
}
              
            
!

JS

              
                /*
 * Keypad Module
 * Author: Rob Hameetman
 * 
 * Hey! I'm always looking for ways to improve my code.
 * If you have any suggestions, I would be truly grateful 
 * if you would leave a comment below. Thanks!
 */

(function($) {
  $(document).ready(function() {
    
    //Settings
    var maxCharacters = 4,
        passcode = 1138;
    
    //Messages
    var msg = {
      success: 'unlocked',
        error: '_error_'
    }

    //Module
    var module = {
      init: function() {
        this.domCache();
        this.setPrivateMethods();
        this.setEventHandlers();
        this.addEventListeners();
      },

      domCache: function() {
        this.$screen = $('.screen');
        this.$cursor = $('.cursor');
        this.$input = $('.text');
        this.$keypad = $('button');
        this.$values = this.$keypad.html().split('');
      },

      setPrivateMethods: function() {
        this.getInput = function() {
          return module.$input.html();
        };
        
        this.getInputLength = function() {
          var input = module.getInput();
          return input.length;
        };
        
        this.messageDisplayed = function() {
          return (module.getInput() === msg.success || module.getInput() === msg.error) ? true : false;
        }
        
        this.showCursor = function() {
          module.$cursor.css({
              'display':'block'
            });
        };
        
        this.updateCursor = function() {
          var characters = module.getInputLength();
          
          if (characters < maxCharacters) {
            var shift = (characters * 16) + 10;
            module.$cursor.css({
              'left': shift + 'px'
            });
          } else {
            module.$cursor.css({
              'left': '10px',
              'display':'none'
            });
          }
        };

        this.authenticate = function() {
          var input = module.getInput(),
              inputNumber = +input;
  
          if (inputNumber === passcode) {
            module.clearScreen();
            module.pushToScreen(msg.success);
            
            setTimeout(function() {
              module.clearScreen();
              module.showCursor();
            }, 2000);
          } else if (input.length === maxCharacters) {
            module.clearScreen();
            module.pushToScreen(msg.error);

            setTimeout(function() {
              module.clearScreen();
              module.showCursor();
            }, 2000);
          }
        };

        this.pushToScreen = function(input) {
          module.$input.css({
            'opacity': '1'
          });
          module.$input.append(input);
        };

        this.removeLastDigit = function() {
          var input = module.$input.text();
          input = input.slice(0, -1);
          module.$input.text(input);
        };
        
        this.clearScreen = function() {
          module.$input.text('');
        };
      },
      
      setEventHandlers: function() {
        this.keypressHandler = function(e) {
          var reg = /^\d$/,
              backspace = 8,
              key,
              isDigit;
          
          if (e.which === backspace) {
            e.preventDefault();
            module.removeLastDigit();
          } else {
            key = e.which - 48;
          }

          isDigit = reg.test(key);

          if (!isDigit) {
            key = undefined;
          }
          
          if (key) {
            if (!module.messageDisplayed()) {
              module.pushToScreen(key);
            }
            module.authenticate();
            module.updateCursor();
          }
        };
        
        this.clickHandler =  function(e) {
          var target = e.target,
              key = target.innerHTML;
          
          if (key === 'DEL') {
            module.removeLastDigit();
          } else if (!module.messageDisplayed()) {
            module.pushToScreen(key);
          }
          
          module.authenticate();
          module.updateCursor();
        };
      },
      
      addEventListeners: function() {
        $(document).on('keypress', this.keypressHandler);
        this.$keypad.on('click.keypad', module.clickHandler);
      }
    };
    
    module.init();
  });
})(jQuery);
              
            
!
999px

Console