cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

            
              <!-- 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
🕑 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