cssAudio - ActiveCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

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.

            
              <div class="calculator">
  <div class="input-prepend">
    <span class="prepend" id="currentOperator"></span>
    <input class="value" disabled="disabled" id="value" value="0" type="number" ng-model="calcScreen" />
  </div>
  <div class="keypad">
    <span data-num="1" class="btn">1</span>
    <span data-num="2" class="btn">2</span>
    <span data-num="3" class="btn">3</span>
    <span data-operator="&plus;" class="btn btn-function">&plus;</span>
    
    <span data-num="4" class="btn">4</span>
    <span data-num="5" class="btn">5</span>
    <span data-num="6" class="btn">6</span>
    <span data-operator="&minus;" class="btn btn-function">&minus;</span>
    
    <span data-num="7" class="btn">7</span>
    <span data-num="8" class="btn">8</span>
    <span data-num="9" class="btn">9</span>
    <span data-operator="&times;" class="btn btn-function">&times;</span>
    
    <span id="clear" class="btn btn-function">c</span>
    <span data-num="0" class="btn">0</span>
    <span id="neg" class="btn btn-function">-</span>
    <span data-operator="&divide;" class="btn btn-function">&divide;</span>
    
    <span data-equals="=" class="btn btn-block">=</span>
  </div>
</div>

<div class="debug">
  <div>Key: <span id="key"></span></div>
  <div>Current: <span id="current"></span></div>
  <div>Previous: <span id="previous"></span></div>
  <div>Operator: <span id="operator"></span></div>
  <div>newInput: <span id="newInput"></span></div>
</div>
            
          
!
            
              @import "compass/css3";

@import "compass";
@import "compass/css3/user-interface"; // For the user-select mixin

// Variables
// ------------------

// Global
$baseFontSize:      20px;
$baseLineHeight:    $baseFontSize;
$blue:              rgba(4,131,163,1);
$bkgd-color:        #827d86;

// Calculator
$calc-height:        370px;
$calc-width:         256px;
$calc-color:         #cdc6c0;
$calc-padding:       20px;
$calc-borderRadius:  20px;

// Value
$value-size:         40px;
$value-color:        $calc-color + 50;

// Buttons
$btn-size:           45px;
$btn-font-size:      20px;
$btn-color:          $calc-color;
$btn-block-color:    #f5b330;
$btn-text-color:     $bkgd-color - 50;

// Mixins
// ------------------

@mixin depth-effect($inner-shadows: $btn-color, $outer-shadows: $calc-color) {
  @include box-shadow (
    // Drop shadow
    0 0 2px rgba(darken($outer-shadows, 100%), 1),  
    
    //Top light
    0 10px 5px -5px rgba($inner-shadows + 50, 1) inset,   

    //Bottom shadow
    0 -10px 5px -8px rgba($inner-shadows - 80, 1) inset,
    
    // All the way around for depth 
    0 0 2px 0 rgba($inner-shadows - 200, .5) inset        
  ); 
  &:active {
    @include box-shadow (
      // Drop shadow
      0 0 2px rgba(darken($outer-shadows, 100%), 1),  
      
      //Top light
      0 5px 5px -5px rgba($inner-shadows + 50, 1) inset,   
  
      //Bottom shadow
      0 -5px 5px -8px rgba($inner-shadows - 80, 1) inset,    
      
      // All the way around for depth 
      0 0 6px -1px rgba($inner-shadows - 200, .5) inset        
    ); 
  }
}

@mixin bkgd-grad($grad-color: $calc-color) {
  background-color: $grad-color;
  @include filter-gradient($grad-color + 30, $grad-color - 30, vertical);
  @include background-image(linear-gradient(top, $grad-color + 30, $grad-color - 30));
}

// Styles
// ------------------

html {
  height: 100%;
}

body {
  height: 100%;
  width: 100%;
  background-color: $bkgd-color; 
  @include filter-gradient(#0483a3, #002733, horizontal); 
  $experimental-support-for-svg: true;
  @include background-image(radial-gradient(top, circle cover,  $bkgd-color 0%, darken($bkgd-color, 15%) 39%, darken($bkgd-color, 23%) 100%));
  position: relative;
  font-size: $baseFontSize;
  line-height: $baseLineHeight;
  background-attachment: fixed;
}

a {
  text-decoration: underline;
}

$calc-grad-top:     $calc-color + 30;
$calc-grad-bottom:  $calc-color - 30;

.calculator {
  @include box-sizing(border-box);
  @include border-radius($calc-borderRadius);
  @include bkgd-grad;
  @include user-select(none);
  @include rotate3d(76%);
  overflow: hidden;
  width: $calc-width;
  height: $calc-height;
  padding: 20px;
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: -$calc-height / 2;
  margin-left: -$calc-width / 2;

  
  @include box-shadow (
    // Drop shadow
    0 10px 40px rgba($bkgd-color - 100, .8),  
    
    //Top light
    0 10px 5px -5px rgba($calc-color + 70, 1) inset,   

    //Bottom shadow
    0 -10px 5px -8px rgba($calc-color - 70, 1) inset,  
    
    // All the way around for depth 
    0 0 8px -1px rgba($calc-color - 200, 1) inset        
  ); 
  



}

.input-prepend { 
  position: relative; 
  .prepend {
    position: absolute;
    top: 10px;
    left: 10px;
    color: $calc-color - 40
  }
}

.value,
.value[disabled=disabled] {
  @include box-sizing(border-box);
  @include bkgd-grad($value-color);
  @include box-shadow(
    0 0 8px 0 rgba($calc-color - 80, .4) inset  
  );
  width: 100%;
  margin-bottom: 20px;
  height: $value-size;
  padding: 5px 10px;
  text-align: right;
  border: 1px solid $calc-color - 30;
  color: $btn-text-color;
}

.btn {
  @include border-radius(10px);
  @include depth-effect();
  @include box-sizing(border-box);
  @include single-transition(color);
  @include bkgd-grad($btn-color);
  @include text-shadow(1px 1px 0 rgba($btn-color + 20, 1));
  
  border: 1px solid darken($btn-color, 40%);
  color: $btn-text-color;
  cursor: pointer;
  display: inline-block;
  float: left;
  font-size: $btn-font-size;
  font-weight: bold;
  height: $btn-size;
  line-height: $btn-size;
  margin: 0 6px 12px;
  padding: 0;
  text-align: center;
  width: $btn-size;
  
  
  // Last Column of buttons
  &:nth-child(4n) {
    margin-right: 0;
  }
  
  // First Column of Buttons
  &:nth-child(4n - 3) {
    margin-left: 0;
  }
  
  &:hover {
    @include bkgd-grad($btn-color + 10);
  }
  
}

.btn-function {
  @include bkgd-grad($btn-color - 25);
  @include depth-effect($btn-color - 20);
  line-height: $btn-size - 4;
  &:hover {
    @include bkgd-grad($btn-color - 15);
  }
}

.btn-block {
  @extend .btn;
  width: 100%;
  margin: 0;
  
  color: #fff;
  @include text-shadow(1px 1px 0 rgba($btn-block-color - 50, 1));
  
  background: $btn-block-color;
  @include depth-effect($btn-block-color);
  @include bkgd-grad($btn-block-color);
  &:hover { @include bkgd-grad($btn-block-color + 5); }
}

// Other stuff
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.debug {
  display: none;
  position: absolute;
  top: 10px;
  left: 10px;
  .red {color: red;}
}
            
          
!
            
              #Storing elements  
number = operator = prevVal = curVal = keyVal = null
screen         = $('#value')
showOperator   = $('#currentOperator')
newInput       = true
  
$ ->  
  calculate = () ->
    saveCurVal = curVal
    switch operator
      when "+" then curVal = parseInt(prevVal, 10) + parseInt(curVal, 10)
      when "−" then curVal = parseInt(prevVal, 10) - parseInt(curVal, 10)
      when "×" then curVal = parseInt(prevVal, 10) * parseInt(curVal, 10)
      when "÷" then curVal = parseInt(prevVal, 10) / parseInt(curVal, 10)
    
    prevVal = saveCurVal
    screen.val(curVal)
    keyVal = null
  
  debug = () ->
    $('#key').text(keyVal)
    $('#current').text(curVal)
    $('#previous').text(prevVal)
    $('#operator').text(operator)
    $('#newInput').text(newInput)
    
          
  pushNumber =  $('[data-num]').click ->         
    keyVal = $(this).data('num')

    if newInput
      if curVal 
        prevVal = screen.val()
      screen.val(keyVal)
      newInput = false
    else
      screen.val(screen.val() + keyVal)
    curVal = screen.val()      
    debug()
      
  pushOperator = $('[data-operator]').click ->
    if prevVal and !newInput
      calculate() 
    newInput = true
    
    operator = $(this).data('operator')
    showOperator.text(operator)
    debug()
      
  pushEquals = $('[data-equals]').click ->
    calculate()
    showOperator.empty()
    newInput = true
    
  pushClear = $('#clear').click ->
    prevVal = curVal = operator = null
    newInput = true
    showOperator.empty()
    screen.val(0)
          
  pushNegative = $('#neg').click ->
    curVal = 0 - parseInt(curVal, 10)
    screen.val(curVal)
            
          
!
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