cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <!-- 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>
            
          
!
            
              $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;}
}
            
          
!
            
              /*
 * 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
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console