Advertisement
Guest User

sesudah edit

a guest
Jul 16th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. <html>
  2. <head>
  3. <style type="text/css">
  4.  
  5. * {
  6. margin: 0;
  7. padding: 0;
  8. box-sizing: border-box;
  9.  
  10. font: bold 14px Arial, sans-serif;
  11. }
  12.  
  13. html {
  14. background-image: url('https://imgur.com/r4RhUOv');
  15. height: 100%;
  16. background: white;
  17. background: radial-gradient(circle, #E6E6FA 20%, #ccc);
  18. background-size: cover;
  19. }
  20.  
  21. #calculator {
  22. width: 325px;
  23. height: auto;
  24.  
  25. margin: 10px auto;
  26. padding: 20px 20px 9px;
  27.  
  28. background: #008000;
  29. background: linear-gradient(#008000, #ADFF2F);
  30. border-radius: 3px;
  31. box-shadow: 0px 4px #808080, 0px 10px 15px rgba(0, 0, 0, 0.2);
  32. }
  33.  
  34. .top span.clear {
  35. float: left;
  36. }
  37.  
  38. .top .screen {
  39. height: 40px;
  40. width: 212px;
  41. float: right;
  42. padding: 0 10px;
  43. background: rgba(0, 0, 0, 0.2);
  44. border-radius: 3px;
  45. box-shadow: inset 0px 4px rgba(0, 0, 0, 0.2);
  46. font-size: 17px;
  47. line-height: 40px;
  48. color: white;
  49. text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
  50. text-align: right;
  51. letter-spacing: 1px;
  52. }
  53.  
  54. .keys, .top {overflow: hidden;}
  55. .keys span, .top span.clear {
  56. float: left;
  57. position: relative;
  58. top: 0;
  59.  
  60. cursor: pointer;
  61.  
  62. width: 66px;
  63. height: 36px;
  64.  
  65. background: Lightseagreen;
  66. border-radius: 3px;
  67. box-shadow: 0px 4px rgba(0, 0, 0, 0.2);
  68.  
  69. margin: 0 7px 11px 0;
  70.  
  71. color: #888;
  72. line-height: 36px;
  73. text-align: center;
  74.  
  75. user-select: none;
  76. transition: all 0.2s ease;
  77. }
  78. .keys span.operator {
  79. background: #87CEEB;
  80.  
  81.  
  82. margin-right: 0;
  83. }
  84.  
  85. .keys span.eval {
  86. background: #00FF7F;
  87. box-shadow: 0px 4px #9da853;
  88. color: #888e5f;
  89. }
  90.  
  91. .top span.clear {
  92. background: #40E0D0;
  93. box-shadow: 0px 4px #708090;
  94. color: white;
  95. }
  96.  
  97. /* Some hover effects */
  98. .keys span:hover {
  99. background: #9c89f6;
  100. box-shadow: 0px 4px #6b54d3;
  101. color: white;
  102. }
  103.  
  104. .keys span.eval:hover {
  105. background: #abb850;
  106. box-shadow: 0px 4px #717a33;
  107. color: #ffffff;
  108. }
  109.  
  110. .top span.clear:hover {
  111. background: #f68991;
  112. box-shadow: 0px 4px #d3545d;
  113. color: white;
  114. }
  115.  
  116. .keys span:active {
  117. box-shadow: 0px 0px #6b54d3;
  118. top: 4px;
  119. }
  120.  
  121. .keys span.eval:active {
  122. box-shadow: 0px 0px #717a33;
  123. top: 4px;
  124. }
  125.  
  126. .top span.clear:active {
  127. top: 4px;
  128. box-shadow: 0px 0px #d3545d;
  129. }
  130. </style>
  131. </head>
  132. <body style="background-image: url('https://i.imgur.com/r4RhUOv.png')">
  133. <div id="calculator">
  134. <!-- Screen and clear key -->
  135. <div class="top">
  136. <span class="clear">C</span>
  137. <div class="screen"></div>
  138. </div>
  139.  
  140. <div class="keys">
  141. <!-- operators and other keys -->
  142. <span>7</span>
  143. <span>8</span>
  144. <span>9</span>
  145. <span class="operator">+</span>
  146. <span>4</span>
  147. <span>5</span>
  148. <span>6</span>
  149. <span class="operator">-</span>
  150. <span>1</span>
  151. <span>2</span>
  152. <span>3</span>
  153. <span class="operator">÷</span>
  154. <span>0</span>
  155. <span>.</span>
  156. <span class="eval">=</span>
  157. <span class="operator">x</span>
  158. </div>
  159. </div>
  160.  
  161. <!-- PrefixFree -->
  162. <script type="text/javascript">
  163. var keys = document.querySelectorAll('#calculator span');
  164. var operators = ['+', '-', 'x', '÷'];
  165. var decimalAdded = false;
  166.  
  167. for(var i = 0; i < keys.length; i++) {
  168. keys[i].onclick = function(e) {
  169. var input = document.querySelector('.screen');
  170. var inputVal = input.innerHTML;
  171. var btnVal = this.innerHTML;
  172.  
  173. if(btnVal == 'C') {
  174. input.innerHTML = '';
  175. decimalAdded = false;
  176. }
  177.  
  178. else if(btnVal == '=') {
  179. var equation = inputVal;
  180. var lastChar = equation[equation.length - 1];
  181. equation = equation.replace(/x/g, '*').replace(/÷/g, '/');
  182. if(operators.indexOf(lastChar) > -1 || lastChar == '.')
  183. equation = equation.replace(/.$/, '');
  184.  
  185. if(equation)
  186. input.innerHTML = eval(equation);
  187.  
  188. decimalAdded = false;
  189. }
  190.  
  191. else if(operators.indexOf(btnVal) > -1) {
  192. var lastChar = inputVal[inputVal.length - 1];
  193. if(inputVal != '' && operators.indexOf(lastChar) == -1)
  194. input.innerHTML += btnVal;
  195. else if(inputVal == '' && btnVal == '-')
  196. input.innerHTML += btnVal;
  197. if(operators.indexOf(lastChar) > -1 && inputVal.length > 1) {
  198. input.innerHTML = inputVal.replace(/.$/, btnVal);
  199. }
  200. decimalAdded =false;
  201. }
  202. else if(btnVal == '.') {
  203. if(!decimalAdded) {
  204. input.innerHTML += btnVal;
  205. decimalAdded = true;
  206. }
  207. }
  208. else {
  209. input.innerHTML += btnVal;
  210. }
  211. e.preventDefault();
  212. }
  213. }
  214. </script>
  215. </body>
  216. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement