B站視頻:https://www.bilibili.com/video/BV1Kp4y167iX
十分鐘實作炫酷透明計算器,CSS3+JavaScript實作3D炫酷計算器
今天帶大家實作了一個炫酷的透明計算器,實作的程序中需要用到vanillatiltjs,一個平滑的3D傾斜javascript庫,具體的使用和下載地址如下:https://micku7zu.github.io/vanilla-tilt.js/
實作代碼如下:
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>炫酷透明計算器:公眾號AlbertYang</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div class="container">
<form class="calculator" name="calc">
<input type="text" readonly="true" class="value" name="txt" />
<span class="num clear" onclick="document.calc.txt.value = ''">C</span>
<span class="num" onclick="document.calc.txt.value += '/'">/</span>
<span class="num" onclick="document.calc.txt.value += '*'">*</span>
<span class="num" onclick="document.calc.txt.value += '7'">7</span>
<span class="num" onclick="document.calc.txt.value += '8'">8</span>
<span class="num" onclick="document.calc.txt.value += '9'">9</span>
<span class="num" onclick="document.calc.txt.value += '-'">-</span>
<span class="num" onclick="document.calc.txt.value += '4'">4</span>
<span class="num" onclick="document.calc.txt.value += '5'">5</span>
<span class="num" onclick="document.calc.txt.value += '6'">6</span>
<span class="num" onclick="document.calc.txt.value += '+'">+</span>
<span class="num" onclick="document.calc.txt.value += '1'">1</span>
<span class="num" onclick="document.calc.txt.value += '2'">2</span>
<span class="num" onclick="document.calc.txt.value += '3'">3</span>
<span class="num" onclick="document.calc.txt.value += '0'">0</span>
<span class="num" onclick="document.calc.txt.value += '00'">00</span>
<span class="num" onclick="document.calc.txt.value += '.'">.</span>
<span class="num equal" onclick="document.calc.txt.value = eval(document.calc.txt.value)">=</span>
</form>
</div>
<script type="text/javascript" src="vanilla-tilt.js"></script>
<script type="text/javascript">
VanillaTilt.init(document.querySelector(".container"), {
max: 15,
speed: 400,
glare: true,
easing: "cubic-bezier(.03,.98,.52,.99)",
"max-glare": 0.05
});
</script>
</body>
</html>
CSS:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: darkslateblue;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(#e91e63, #ffc107);
clip-path: circle(22% at 30% 20%);
}
body::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(#ffffff, #da00ff);
clip-path: circle(20% at 70% 90%);
}
.container {
position: relative;
background: rgba(255, 255, 255, 0.05);
border-radius: 6px;
overflow: hidden;
z-index: 100;
border-top: 1px solid rgba(255, 255, 255, 0.2);
border-left: 1px solid rgba(255, 255, 255, 0.2);
box-shadow: 5px 5px 30px rgba(0, 0, 0, 0.3);
}
.container .calculator {
position: relative;
display: grid;
}
.container .calculator .value {
grid-column: span 4;
height: 150px;
width: 320px;
text-align: right;
border: none;
outline: none;
padding: 10px;
font-size: 30px;
background-color: transparent;
color: #FFFFFF;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
border-right: 1px solid rgba(255, 255, 255, 0.05);
}
.container .calculator span {
display: grid;
place-items: center;
height: 80px;
width: 80px;
color: #fff;
font-weight: 500;
font-size: 20px;
cursor: pointer;
user-select: none;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
border-right: 1px solid rgba(255, 255, 255, 0.05);
transition: 0.5s;
}
.container .calculator span:hover {
transition: 0s;
background: rgba(255, 255, 255, 0.05);
}
.container .calculator span:active {
background: #00BCD4;
color: black;
font-size: 24px;
font-weight: 600;
}
.container .calculator .equal,
.container .calculator .clear {
grid-column: span 2;
width: 160px;
background: rgba(255, 255, 255, 0.05);
}

由于本人能力和知識有限,如果有寫的不對的地方,還請各位大佬批評指正,如果想繼續學習提高,歡迎關注我,每天學習進步一點點,就是領先的開始,加油,如果覺得本文對你有幫助的話,歡迎轉發,評論,點贊!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/237254.html
標籤:其他
上一篇:vue + axios 實作分頁引數傳遞,高級搜索功能實作
下一篇:VScode代碼自動補全問題
