十分钟实现炫酷透明计算器,CSS3+JavaScript实现3D炫酷计算器

举报
AlbertYang 发表于 2021/02/03 00:17:19 2021/02/03
【摘要】 B站视频:https://www.bilibili.com/video/BV1Kp4y167iX 十分钟实现炫酷透明计算器,CSS3+JavaScript实现3D炫酷计算器 今天带大家实现了一个炫酷的透明计算器,实现的过程中需要用到vanillatiltjs,一个平滑的3D倾斜javascript库,具体的使用和下载地址如下:https://micku7zu.g...

B站视频:https://www.bilibili.com/video/BV1Kp4y167iX

十分钟实现炫酷透明计算器,CSS3+JavaScript实现3D炫酷计算器

今天带大家实现了一个炫酷的透明计算器,实现的过程中需要用到vanillatiltjs,一个平滑的3D倾斜javascript库,具体的使用和下载地址如下:https://micku7zu.github.io/vanilla-tilt.js/

实现代码如下:

HTML:


  
  
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>炫酷透明计算器:公众号AlbertYang</title>
  6. <link rel="stylesheet" type="text/css" href="style.css" />
  7. </head>
  8. <body>
  9. <div class="container">
  10. <form class="calculator" name="calc">
  11. <input type="text" readonly="true" class="value" name="txt" />
  12. <span class="num clear" onclick="document.calc.txt.value = ''">C</span>
  13. <span class="num" onclick="document.calc.txt.value += '/'">/</span>
  14. <span class="num" onclick="document.calc.txt.value += '*'">*</span>
  15. <span class="num" onclick="document.calc.txt.value += '7'">7</span>
  16. <span class="num" onclick="document.calc.txt.value += '8'">8</span>
  17. <span class="num" onclick="document.calc.txt.value += '9'">9</span>
  18. <span class="num" onclick="document.calc.txt.value += '-'">-</span>
  19. <span class="num" onclick="document.calc.txt.value += '4'">4</span>
  20. <span class="num" onclick="document.calc.txt.value += '5'">5</span>
  21. <span class="num" onclick="document.calc.txt.value += '6'">6</span>
  22. <span class="num" onclick="document.calc.txt.value += '+'">+</span>
  23. <span class="num" onclick="document.calc.txt.value += '1'">1</span>
  24. <span class="num" onclick="document.calc.txt.value += '2'">2</span>
  25. <span class="num" onclick="document.calc.txt.value += '3'">3</span>
  26. <span class="num" onclick="document.calc.txt.value += '0'">0</span>
  27. <span class="num" onclick="document.calc.txt.value += '00'">00</span>
  28. <span class="num" onclick="document.calc.txt.value += '.'">.</span>
  29. <span class="num equal" onclick="document.calc.txt.value = eval(document.calc.txt.value)">=</span>
  30. </form>
  31. </div>
  32. <script type="text/javascript" src="vanilla-tilt.js"></script>
  33. <script type="text/javascript">
  34. VanillaTilt.init(document.querySelector(".container"), {
  35. max: 15,
  36. speed: 400,
  37. glare: true,
  38. easing: "cubic-bezier(.03,.98,.52,.99)",
  39. "max-glare": 0.05
  40. });
  41. </script>
  42. </body>
  43. </html>

CSS:


  
  
  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. body {
  7. display: flex;
  8. justify-content: center;
  9. align-items: center;
  10. min-height: 100vh;
  11. background-color: darkslateblue;
  12. }
  13. body::before {
  14. content: '';
  15. position: absolute;
  16. top: 0;
  17. left: 0;
  18. width: 100%;
  19. height: 100%;
  20. background: linear-gradient(#e91e63, #ffc107);
  21. clip-path: circle(22% at 30% 20%);
  22. }
  23. body::after {
  24. content: '';
  25. position: absolute;
  26. top: 0;
  27. left: 0;
  28. width: 100%;
  29. height: 100%;
  30. background: linear-gradient(#ffffff, #da00ff);
  31. clip-path: circle(20% at 70% 90%);
  32. }
  33. .container {
  34. position: relative;
  35. background: rgba(255, 255, 255, 0.05);
  36. border-radius: 6px;
  37. overflow: hidden;
  38. z-index: 100;
  39. border-top: 1px solid rgba(255, 255, 255, 0.2);
  40. border-left: 1px solid rgba(255, 255, 255, 0.2);
  41. box-shadow: 5px 5px 30px rgba(0, 0, 0, 0.3);
  42. }
  43. .container .calculator {
  44. position: relative;
  45. display: grid;
  46. }
  47. .container .calculator .value {
  48. grid-column: span 4;
  49. height: 150px;
  50. width: 320px;
  51. text-align: right;
  52. border: none;
  53. outline: none;
  54. padding: 10px;
  55. font-size: 30px;
  56. background-color: transparent;
  57. color: #FFFFFF;
  58. border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  59. border-right: 1px solid rgba(255, 255, 255, 0.05);
  60. }
  61. .container .calculator span {
  62. display: grid;
  63. place-items: center;
  64. height: 80px;
  65. width: 80px;
  66. color: #fff;
  67. font-weight: 500;
  68. font-size: 20px;
  69. cursor: pointer;
  70. user-select: none;
  71. border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  72. border-right: 1px solid rgba(255, 255, 255, 0.05);
  73. transition: 0.5s;
  74. }
  75. .container .calculator span:hover {
  76. transition: 0s;
  77. background: rgba(255, 255, 255, 0.05);
  78. }
  79. .container .calculator span:active {
  80. background: #00BCD4;
  81. color: black;
  82. font-size: 24px;
  83. font-weight: 600;
  84. }
  85. .container .calculator .equal,
  86. .container .calculator .clear {
  87. grid-column: span 2;
  88. width: 160px;
  89. background: rgba(255, 255, 255, 0.05);
  90. }

由于本人能力和知识有限,如果有写的不对的地方,还请各位大佬批评指正。如果想继续学习提高,欢迎关注我,每天学习进步一点点,就是领先的开始,加油。如果觉得本文对你有帮助的话,欢迎转发,评论,点赞!!!

文章来源: albertyang.blog.csdn.net,作者:Albert Yang,版权归原作者所有,如需转载,请联系作者。

原文链接:albertyang.blog.csdn.net/article/details/111302823

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。