Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

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

              
                <div class="container">
  
  <div id="calc-shadow">
    <div id="calc">

      <div id="outer-face">
        <div id="model"><span id="logo">C<span id="logo-fix">anon</span></span>&nbsp;&nbsp;&nbsp;&nbsp;LS-82Z</div>
        <div id="description">
          <span id="desc-text">SOLAR AND BATTERY</span>
          <span id="asterisk"> &#10058;</span><span id="star">&star;</span>
        </div>
        <div id="solar-array">
          <div class="solar-panel"></div>
          <div class="solar-panel"></div>
          <div class="solar-panel"></div>
          <div class="solar-panel"></div>
        </div>
        <div id="inner-face">
          <div id="display">
            <div id="digits">
              <!-- digits go here -->
            </div>
          </div>
        </div><!-- end inner-face -->
      </div><!-- end outer-face -->
      
      
      
<!--   BUTTONS     -->
      
      <div id="buttons">
        <!-- 1st row -->
        <button class="operation" id="percent" value="percent">
          <div class="row">
            <div id="m-space" class="col">%</div>
            <div id="o-space" class="col">
              <div>&plus;</div>
              <div>&minus;</div>
            </div>
        </button>
        <button class="number" value="7">7</button>
        <button class="number" value="8">8</button>
        <button class="number" value="9">9</button>
        <button class="operation" id="times" value="times">&times</button>
        <button class="operation" id="divide" value="divide">&divide</button>
        
        <!-- 2nd row -->
        <button class="operation" id="square-root" value="sqrt">&Sqrt;</button>
        <button class="number" value="4">4</button>
        <button class="number" value="5">5</button>
        <button class="number" value="6">6</button>
        <button class="operation" id="minus" value="minus">&minus;</button>
        <button class="memory" id="rm-cm" value="rm-cm">
          <div class="row" id="rm">RM</div>
          <div class="row" id="cm">CM</div>
        </button>
        
        <!-- 3rd row -->
        <button class="clear" id="on-c" value="on-c">
          <div class="row" id="on">ON</div>
          <div class="row" id="c">C</div>
        </button>
        <button class="number" value="1">1</button>
        <button class="number" value="2">2</button>
        <button class="number" value="3">3</button>
        <button style="visibility: hidden;"></button>
        <button class="memory" id="m-minus" value="m-minus">
          <div class="row">
            <div id="m-space" class="col">M</div>
            <div id="o-space" class="col">
              <div>&minus;</div>
              <div>&equals;</div>
            </div>
        </button>
        
        <!-- 4th row -->
        <button class="clear" value="cl">
          <div class="row" id="cl">C<span id="smaller-l">l</span></div>
        </button>
        <button class="number"                    value="0">0</button>
        <button class="number"    id="decimal"    value=".">&middot;</button>
        <button class="number"    id="equals"     value="equals">&equals;</button>
        <button class="operation" id="plus"       value="plus">&plus;</button>
        <button class="memory"    id="m-plus" value="m-plus">
          <div class="row">
            <div class="col" id="m-space">M</div>
            <div class="col" id="o-space">
              <div>&plus;</div>
              <div>&equals;</div>
            </div>
        </button>
      </div> <!-- end buttons --> 
    </div> <!-- end calc -->
  </div> <!-- end calc-shadow -->
</div><!-- end container -->
              
            
!

CSS

              
                @font-face {
  font-family: 'Digital';
  src: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/1268753/digital-7%20(mono).ttf')
  format('truetype');
}

@font-face {
  font-family: 'CANON';
  src: url('https://cdn.rawgit.com/candlefish/candlefish.github.io/b10b2410/CANON.ttf')
       format('truetype');
}


body {
  background-color: #d2b48c;
}

#calc, #calc-shadow {
  width: 400px;
  height: 525px;
  border-top-left-radius: 15px;
  border-top-right-radius: 15px;
  border-bottom-right-radius: 195px 35px;
  border-bottom-left-radius: 195px 35px;
}

#calc-shadow {
  position: relative;
  box-shadow: 6px 6px 5px #695A46;
  margin: 0 auto;
  -ms-transform: translate(0,80px); /* IE 9 */
  -webkit-transform: translate(0,80px); /* Safari */
  transform: translate(0,80px);
}

#calc {
  background-color: #E6E7EA;
  -moz-box-shadow: inset 4px 4px 4px rgba(230, 231, 234, .4),
                   inset -4px -4px 4px rgba(0, 0, 0, .4);
  -webkit-box-shadow: inset 4px 4px 4px rgba(230, 231, 234, .4),
                      inset -4px -4px 4px rgba(0, 0, 0, .4);
}

#outer-face, #inner-face {
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  border-bottom-right-radius: 195px 35px;
  border-bottom-left-radius: 195px 35px;
}

#outer-face {
  margin: 0 auto;
  background-color: #39434D;
  width: 390px;
  height: 200px;
  -ms-transform: translate(0,5px);
  -webkit-transform: translate(0,5px);
  transform: translate(0,5px);
}

#model {
  position: absolute;
  border-bottom: 2px solid;
  color: #BEC5CF;
  line-height: 20px;
  -ms-transform: translate(25px,5px);
  -webkit-transform: translate(25px,5px);
  transform: translate(25px,9px);
}

#logo {
  font-family: 'Canon';
  font-size: 23px;
  letter-spacing: -1px;
}

#logo-fix {
  letter-spacing: 1.25px;
}

#description {
  position: absolute;
  color: #BEC5CF;
  -ms-transform: translate(25px,32px); /* IE 9 */
  -webkit-transform: translate(25px,32px); /* Safari */
  transform: translate(25px,32px);
}

#desc-text {
  font-size: 10px;
  line-height: 1.6em;
  vertical-align: top;
}

#asterisk {
  font-size: 16px;
  line-height: 0.8em;
  vertical-align: top;
}

#star {
  font-size: 13px;
  line-height: 1.1em;
  vertical-align: top;
}

#solar-array {
  position: absolute;
  display: inline-block;
  -ms-transform: translate(240px,10px);
  -webkit-transform: translate(240px,10px);
  transform: translate(240px,10px);
}

.solar-panel {
  float: left;
  margin-right: 1px;
  background-color: #514348;
  width: 24px;
  height: 32px;
  -moz-box-shadow: inset 1px 1px 1px rgba(30, 16, 21, .4);
  -webkit-box-shadow: inset 1px 1px 1px rgba(30, 16, 21, .4);
}

#inner-face {
  position: absolute;
  background-color: #BEC5CF;
  width: 360px;
  height: 140px;
  -ms-transform: translate(15px,50px);
  -webkit-transform: translate(15px,50px);
  transform: translate(15px,50px);
}

/********** DISPLAY ***********/

#display {
  overflow: hidden;
  color: black;
  text-shadow: 2px 2px #333;
  border: 5px solid #EAEAEA;
  background-color: #56635C;
  width: 300px;
  height: 98px;
  -ms-transform: translate(30px,15px);
  -webkit-transform: translate(30px,15px);
  transform: translate(30px,15px);
  -webkit-box-shadow: 0 0 3px #1D0E00;
  box-shadow: 0 0 3px #1D0E00;
}

#digits {
  font-family: 'Digital';
  font-size: 75px;
  line-height: 1em;
  width: 300px;
  height: 98px;
  padding-right: 16px;
  text-align: right;
  transform: scale(1, 1.4);
  -webkit-transform: scale(1, 1.4); /* Safari and Chrome */
  -moz-transform: scale(1, 1.4); /* Firefox */
  -ms-transform: scale(1, 1.4); /* IE 9+ */
  -o-transform: scale(1, 1.4); /* Opera */
}

#dot {
  letter-spacing: -12px;
}


/*********** BUTTONS ***********/

#buttons {
  position: absolute;
  width: 360px;
  transform: translate(20px,35px);
}

button {
  text-align: center;
  font-family: 'Open Sans', sans-serif;
  font-weight: regular;
  color: white;
  font-size: 36px;
  line-height: 1em;
  width: 50px;
  height: 50px;
  border-radius: 10px;
  margin: 3.3px;
  margin-bottom: 8px;
  vertical-align: top; /* fixes button text baseline issue */
  padding: 4px; /* fixes weird iOS button layout issue */
}

button:focus {
  outline: none;
}

.number {
  background-color: #6B8AA6;
  box-shadow: 0 3px #1F3E5A;
  border-color: #85A4C0;
}

.operation, .memory {
  font-weight: 400;
  background-color: #3F4B58;
  box-shadow: 0 3px #26323F;
  border-color: #596572;
}

.clear {
  background-color: #BA5482;
  box-shadow: 0 3px #210000;
  border-color: #D46E9C;
}

#times, #divide {
  padding-top: 0;
}

#square-root {
  padding-top: 8px;
}

#rm-cm, #on-c {
  padding-top: 2px;
  font-size: 18px;
  line-height: 0.8em;
}

#rm, #on {
  display: inline-block;
  border-bottom: 2px solid white;
  padding-bottom: 2px;
}

#cm, #c {
  padding-top: 1px;
}

#plus-spacer {
  display: inline-block;
  width: 50;
}

#smaller-l {
  font-size: 34px;
}

#plus {
  height: 110px;
  transform: translate(0, -60px);
}

#m-space {
  font-size: 32px;
  float: left;
  width: 60%;
  padding-left: 8px;
}

#o-space {
  padding-top: 5px;
  font-size: 24px;
  line-height: 0.6em;
  float: left;
  width: 20%;
  display: table-cell;
}

/* Set Chrome line-height to 1.4em so it will agree with Firefox */
@media screen and (-webkit-min-device-pixel-ratio:0) {
  #digits {
    line-height:1.3em;
  }
}
              
            
!

JS

              
                $(function() {
 
  // ******** Define and Initialize Variables ******** //
  var isOn = false;
  var makeNegative = false;
  var displayStr = "";
  var currVal = 0;
  var storedVal = 0;
  var mem = 0;
  var storedOp = "";
  var prevEntry = "0";
  

  // ******** Functions ******** //
  var operators = {
    'plus': function(a, b) { return a + b },
    'minus': function(a, b) { return a - b },
    'times': function(a, b) { return a * b },
    'divide': function(a, b) { return a / b },
    'sqrt': function(a) { return Math.sqrt(a)},
    'percent': function (a, b) { return a * ( b / 100 )}
  };
  
  function ClearAllButMemory() {
    displayStr = "0";
    currVal = 0;
    storedVal = 0;
    storedOp = "";
    prevEntry = "0";
  }
  
  function PrepareStringForDisplay(str) {
    var val = +str;
    
    // Value can't be expressed on this display correctly
    if (val > 99999999 || val < -9999999) return "Error";
    
    var dpos = str.indexOf('.');

    // If it's an integer within expressible range, display it
    if (dpos === -1) return str;
    
    if (isNaN(prevEntry)) {
      // Ignore decimal point in terms of string length
      var charCount = str.length - 1;
      
      // If the value exceeds the display width, round it to fit
      if (charCount > 8) {
        var exp = dpos - 8; // the 10log of the rightmost digit
        val = val.toString().split('e');
        val = Math.round(+(val[0] + 'e' + (val[1] ? (+val[1] - exp) : -exp)));
        // Shift back
        val = val.toString().split('e');
        val = +(val[0] + 'e' + (val[1] ? (+val[1] + exp) : exp));
      }
      str = val.toString();
    }
    
    // Close the gap around the decimal point
    str = str.substr(0, dpos - 1) +
          '<span id="dot">' +
          str[dpos - 1] +
          '.</span>' +
          str.substr(dpos + 1);
 
    return str;
  }
  // ******** END: Functions ******** //
  
  
  
  // ******** Calc Button Click ******** // 
  $('button').click(function() {
    var btnVal = $(this).val();
    
    // Require ON/C button click to start calculator
    if (isOn === false && btnVal !== 'on-c') return;
    isOn = true;
    
    // Require clear after error
    if (displayStr === "Error" && (btnVal !== "on-c" && btnVal !== "cl")) return;
    
    // **** Buttons Switch-Case **** //
    switch(btnVal) {
      // Clear all, including memory
      case 'on-c':
        ClearAllButMemory();
        mem = 0;
        break;

      // Clear last entry, otherwise clear all but memory
      case 'cl':
        if (displayStr == "0" || displayStr == "Error") {
          ClearAllButMemory();
        } else {
          prevEntry = "0";
          displayStr = "0";
        }
        break;
        
      // Recall memory, but clear memory if clicked twice in a row
      case 'rm-cm':
        if (prevEntry !== "rm-cm") {
          displayStr = mem.toString();
          currVal = +displayStr;
        } else {
          displayStr = "0";
          currVal = 0;
          mem = 0;
        }
        prevEntry = "rm-cm";
        break;
        
      case 'm-plus':
      case 'm-minus':
        if (prevEntry === "result") {
          storedOp = "";
          currVal = storedVal;
        }
        storedVal = currVal;
        btnVal === "m-plus" ? mem += currVal : mem -=currVal;
        displayStr = mem.toString();
        currVal = +displayStr;
        storedOp = "";
        prevEntry = "result";
        break;
      
      case '0':
      case '1':
      case '2':
      case '3':  
      case '4':
      case '5':
      case '6':
      case '7':
      case '8':  
      case '9':
        if (isNaN(prevEntry) || displayStr === "0") {
          makeNegative ? displayStr = "-" + btnVal : displayStr = btnVal;
          makeNegative = false;
        } else {
          if (displayStr.length > 7 + (displayStr.indexOf('.') !== -1)) break;
          displayStr += btnVal;
        }
        prevEntry = btnVal;
        currVal = +displayStr;
        break;
      
      case '.':
        if (isNaN(prevEntry)) {
          makeNegative ? displayStr = "-0." : displayStr = "0.";
          makeNegative = false;
          prevEntry = "0";
        } else if (displayStr.indexOf('.') === -1) {
          if (displayStr.length > 7 + (displayStr.indexOf('.') !== -1)) break;
          displayStr += '.';
        }
        break;
        
      case 'percent':
        if (storedOp === "minus" || storedOp === "plus") {
          currVal = operators[btnVal](storedVal, currVal);
        } else {
          currVal = currVal * 0.01;
          displayStr = currVal.toString();
          break;
        }
        displayStr = currVal.toString();
        prevEntry = "result";
        break;

      case 'sqrt': 
        if (prevEntry === "result") {
          storedOp = "";
          currVal = storedVal;
        }
        if (currVal < 0) {
          displayStr = "Error";
          break;
        }
        currVal = +displayStr;
        currVal = Math.sqrt(currVal);
        if (storedVal === 0 || prevEntry === "result") storedVal = currVal;
        displayStr = currVal.toString();
        prevEntry = "result";
        break;

      case 'minus':
        if (prevEntry === "operation" || +displayStr === 0) {
            makeNegative ? makeNegative = false : makeNegative = true;
            break;
          }
      case 'plus':  
      case 'times':
      case 'divide':
        if (isNaN(prevEntry) || prevEntry === "0") {
          storedOp = "";
          currVal = storedVal;
        }
        if (storedOp !== "") { // If there's a stored op, do it
          // Catch division by zero error
          if (storedOp === 'divide' && currVal === 0) {
            displayStr = "Error";
            break;
          }
          // Perform stored operation
          storedVal = operators[storedOp](storedVal, currVal); 
          displayStr = storedVal.toString();
        } else { // Otherwise, it's a new op so just store current value
          storedVal = +displayStr;
        }
        // And, either way, store the operation type
        storedOp = btnVal;
        prevEntry = "operation";
        break;

      case 'equals':
        if (storedOp !== "") { // If there's a stored op, do it
          // Catch division by zero error
          if (storedOp === 'divide' && currVal === 0) {
            displayStr = "Error";
            break;
          }
          // Perform stored operation
          storedVal = operators[storedOp](storedVal, currVal);
          displayStr = storedVal.toString();
        } else {
          // Display current value
          displayStr = currVal.toString();
        }
        prevEntry = "result";
        break;

      default:
        alert("What button was that?!");
        
    } /* END: Buttons Switch-Case */
    
  var lcd = PrepareStringForDisplay(displayStr);
  $('#digits').html(lcd);
    
}) /******** END: Calc Button Click ********/

  
  // Fade the screen with solar array hover
  
  
  $('#solar-array').hover(function () {
    $('#solar-array').click(function(e) {
    e.preventDefault();
    return;
    })
    $('#digits').stop().animate({opacity: 0.1}, 4000);
  }, function () {
    $('#digits').stop().animate({opacity: 1.0}, 1000);
  });
  
});
              
            
!
999px

Console