此内容来自第三方平台 (Dailymotion)。如果此视频侵犯了您的版权,请使用 立即删除 工具。
HTML5 simple calculator(html,css,javascript)
描述
HTML:
CSS:
#calculator {
width: 250px;
height: 350px;
border: 5px solid black;
text-align: center;
background: lightgreen;
margin: 150px auto;
box-shadow: 0px 0px 30px gray;
}
#display {
margin-top: 30px;
margin-bottom: 20px;
width: 220px;
height: 30px;
border: 1px solid red;
box-shadow: 0px 0px 30px red;
text-align: right;
font: 20px bold;
color: blue
}
#keys {
-webkit-appearance: button;
width: 40px;
height: 35px;
margin-left: 10px;
margin-bottom: 10px;
box-shadow: 0px 0px 20px skyblue;
cursor: pointer
}
#keys:hover {
background: yellow;
font-weight: bold;
}
#equal {
-webkit-appearance: none;
width: 90px;
height: 35px;
margin-left: 10px;
margin-bottom: 10px;
box-shadow: 0px 0px 20px skyblue;
cursor: pointer
}
JAVASCRIPT:
"use strict";
// Initilization of calculator screen value
let box = document.getElementById("display");
box.value = "";
// append character to screen
function addToScreen(e) {
box.value += e;
if (e == "c") {
resetScreen();
}
}
// reset screen
function resetScreen() {
box.value = '';
}
// evaluate a mathematical expression string
function answer() {
let s = box.value;
box.value = String(eval(s));
}
function backSpace() {
let s = box.value;
let len = s.length;
if (len > 0) {
s = s.slice(0, len-1);
}
box.value = s;
}
function power(y) {
let x = box.value;
box.value = Math.pow(x, y);
}
Read More: https://codepen.io/At
SOURCES: codepen.io
CSS:
#calculator {
width: 250px;
height: 350px;
border: 5px solid black;
text-align: center;
background: lightgreen;
margin: 150px auto;
box-shadow: 0px 0px 30px gray;
}
#display {
margin-top: 30px;
margin-bottom: 20px;
width: 220px;
height: 30px;
border: 1px solid red;
box-shadow: 0px 0px 30px red;
text-align: right;
font: 20px bold;
color: blue
}
#keys {
-webkit-appearance: button;
width: 40px;
height: 35px;
margin-left: 10px;
margin-bottom: 10px;
box-shadow: 0px 0px 20px skyblue;
cursor: pointer
}
#keys:hover {
background: yellow;
font-weight: bold;
}
#equal {
-webkit-appearance: none;
width: 90px;
height: 35px;
margin-left: 10px;
margin-bottom: 10px;
box-shadow: 0px 0px 20px skyblue;
cursor: pointer
}
JAVASCRIPT:
"use strict";
// Initilization of calculator screen value
let box = document.getElementById("display");
box.value = "";
// append character to screen
function addToScreen(e) {
box.value += e;
if (e == "c") {
resetScreen();
}
}
// reset screen
function resetScreen() {
box.value = '';
}
// evaluate a mathematical expression string
function answer() {
let s = box.value;
box.value = String(eval(s));
}
function backSpace() {
let s = box.value;
let len = s.length;
if (len > 0) {
s = s.slice(0, len-1);
}
box.value = s;
}
function power(y) {
let x = box.value;
box.value = Math.pow(x, y);
}
Read More: https://codepen.io/At
SOURCES: codepen.io
关键词与标签
相关视频
HTML, CSS JavaScript Web Publishing in One Hour a Day, Sams Teach Yourself: Covering HTML5,
craysonardon
How to Create Image Slider in HTML and CSS/Auto image slider/Responsive ImageSlider using CSS and javascript #NOLIMIT CODE
No Limit Code
Glass Effect Navbar pake HTML dan CSS #HTML #html5 #htmlcss #htmlcode #htmlemail #htmlcoding #coding #codinglife #codingisfun
Coding Shorts
Website forums, websites forum,HTML forum, SQL forum, PHP forum, Javascript forum, CSS forum, Servers forum, Minecraft forum, Coding forum, javescript coding forum
jenwhiteeee
Phileas Code - Plateforme d'apprentissage du Front Code - HTML, CSS, Javascript
PhileasCode
Full E-book Web Coding Bible (18 Books in 1 -- HTML, CSS, JavaScript, PHP, SQL, XML, Svg,
dm_d99e72534698ff32a8488cf759461d2c