受iOS启发, jQuery构建Web计算器

  • 源码大小:7.11KB
  • 所需积分:1积分
  • 源码编号:19JP-3409
  • 浏览次数:244次
  • 最后更新:2023年06月10日
  • 所属栏目:其他
本站默认解压密码:19jp.com 或 19jp_com

简介

计算器在我们的日常生活中很方便,用于购物、工作中的计算、在线财务或烹饪食谱。你可以在网上找到无数的在线计算器,用于你的网络应用程序。

如果你是苹果的粉丝,并且使用iPhone,你可能已经看到了iOS中包含的计算器应用程序。这是我见过的最好的计算器之一。

在这篇文章中,我们将使用HTML、CSS和jQuery构建一个干净易用的基于网络的计算器,它的灵感来自iOS计算器应用程序。它具有计算器最基本的功能,如加法、减法、乘法、除法、复位和百分比。

如何使用它:

1.创建一个空容器来容纳计算器。

<div id="calculator"></div>

2.加载必要的JavaScript文件。

<!-- jQuery Is Required -->
<script src="/path/to/cdn/jquery.slim.min.js"></script>

<!-- Core -->
<script src="calculation.js"></script>

<!-- Generate The Calculator -->
<script src="calculator.js"></script>

3.将以下CSS添加到您的网页中。就是这样。

/*============================
  APP DESIGN
============================*/
#calculator {
  min-height: 500px;
  max-height: 550px;
  min-width: 450px;
  max-width: 500px;
  border-radius: 10px 10px 0 0;
  height: auto;
  background-color: #1A1A1D;
  box-shadow: 5px 10px 20px 10px rgb(29, 25, 25);
  display: grid;
  grid-template: "s s s s" 1fr
                 "a a a o" 1fr
                 "n n n o" 1fr
                 "n n n o" 1fr
                 "n n n o" 1fr
                 "n n n o" 1fr
                 / 1fr 1fr 1fr 1fr;
}

/*============================
  CALCULATOR SCREEN
============================*/
.screen {
  width: 100%;
  height: auto;
  grid-area: s;
  background-color: #1A1A1D;
  border-radius: 10px 10px 0 0;
}

.screen p {
  display: inline-block;
  color: white;
  text-align: right;
  width: 100%;
  height: 100%;
  font-size: 2.4rem;
  user-select: none;
}
/*============================
  CALCULATOR BUTTONS
============================*/
button {
  border-radius: 50%;
  width: 75%;
  min-width: 90px;
  height: auto;
  outline: none;
  color: white;
  user-select: none;
  border: 1px transparent solid;
  transition: all 0.3s ease;
}

/*=== BUTTON CONTAINERS===*/
.container {
  justify-items: center;
  grid-gap: 5px;
  padding: 5px 0;
}

.aux {
  grid-area: a;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding-bottom: 0;
}

.operators {
  grid-area: o;
  display: grid;
  grid-template-rows: repeat(5, 1fr);
  padding-right: 5px;
}

.numbers {
  grid-area: n;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(4, 1fr);
}
/*=== AUXILLARY BUTTONS===*/

.auxillary {
  background-color: #9f9fa1;
  color: black;
}

.auxillary:active {
  background-color: #d3d3d4;
}
/*=== OPERATOR BUTTONS===*/
.operator {
  background-color: #C3073F;
}

.operator:active {
  background-color:#a03152;
  color: white;
}

.op-clicked {
  background-color: white;
  color: #C3073F;
}

#division {
  font-size: 1.3em;
}
/*=== NUMBER BUTTONS===*/
.numbers button {
  background-color: #4E4E50;
}

.numbers button:active {
  background-color:  #a09e9e;
  color: black;
}

#zero {
  grid-column: span 2;
  border-radius: 40px 40px;
  min-width: 190px;
  text-align: left;
  text-indent: 15%;
}

预览截图