有趣的HTML实例(十三) 咖啡选择(css+js)

向右看齐 2024-04-28 07:56 167阅读 0赞

一个人追求目标的路途是孤单的,一个人独品辛酸的时候是寂寥的,一个人马不停蹄的追赶着,狂奔着,相信前方是一片光明,我从不放弃希望,就像我对生活的信念,没有人可以动摇。

——《北京青年》

54adb699c22545f18d065f4be5fe1d21.png


目录

一、前言

二、往期作品回顾

三、作品介绍

四、本期代码介绍

五、效果显示

六、编码实现

index.html

style.css

script.js

七、获取源码

公众号获取源码

获取源码?私信?关注?点赞?收藏?


一、前言

在我们的 html 学习过程中,会用到并见识到各种各样的实例,以及各种插件,并且有些 web 网页中的小插件又非常的吸引眼球,提升 web 网页的层次,显得非常好看并且非常使用。在本系列中,我将持续为大家更新有趣且使用的 html 实例,放在 web 网页中,凸显效果。

特点一:都是符合学校或者学生考试期末作业的水平,都是最基础的简单的 html 样例,提升web网页整理效果,都是 div+css 框架原创代码写的,内容包括 js / css,也包含 视频+音乐+flash 等元素的插入…

特点二:内容包括多种丰富类型,例如: 倒计时,404页面,Blog顶置卡片设计 (css+js),To-Do-List设计 (css+js),火柴盒动画 (css),日历便签设计 (css+js),搜索框设计 (css+js),卡片式图片展示 (css+js),咖啡选择 (css+js)……

可满足多种需求,欢迎大家下载!

5493b88af49745b18ffba5c1a291d069.png

#


二、往期作品回顾

有趣的HTML实例(一) 倒计时_Enovo_飞鱼的博客-CSDN博客

有趣的HTML实例(二) 404页面_Enovo_飞鱼的博客-CSDN博客

有趣的HTML实例(三) 加载页面动画_Enovo_飞鱼的博客-CSDN博客

有趣的HTML实例(四) 旋转菜单_Enovo_飞鱼的博客-CSDN博客

有趣的HTML实例(五) 加载页面动画Ⅱ(css)_Enovo_飞鱼的博客-CSDN博客

有趣的HTML实例(六) 卡片翻转时钟_Enovo_飞鱼的博客-CSDN博客

有趣的HTML实例(七) 注册登录界面Ⅱ(css+js)_Enovo_飞鱼的博客-CSDN博客

有趣的HTML实例(八) 一个很有趣的动态背景(css+js)_Enovo_飞鱼的博客-CSDN博客

有趣的HTML实例(九) 文本变形动画(css+js)_Enovo_飞鱼的博客-CSDN博客

有趣的HTML实例(十) 悬停时有旋转效果的图标_Enovo_飞鱼的博客-CSDN博客

有趣的HTML实例(十一) 烟花特效(css+js)_Enovo_飞鱼的博客-CSDN博客

有趣的HTML实例(十二) 早安、晚安动画(css+js)_Enovo_飞鱼的博客-CSDN博客


三、作品介绍

1.作品简介 :HTML响应式布局网站源码!兼容 pc 以及移动端,内涵 js 交互,ui 交互。直接点击即可查看效果!

2.作品编辑:个人主页网页设计题材,代码为 html+css 布局制作,作品下载后可使用任意HTML编辑软件(例如:DW、HBuilder、Vscode 、Sublime 所有编辑器均可使用)。

3.作品技术:使用DIV+CSS制作了网页背景图、鼠标经过及选中导航变色效果、下划线等。


四、本期代码介绍

一款简单的 HTML+ CSS+JS 咖啡选择(css+js) 实例

1、HTML

2、CSS

3、JS

4、舒适的画面感

5、咖啡

6、各种不同类型咖啡点击效果

可通用多种不同情景,放置在web网页上,可以作为跳转页面之后使用


五、效果显示

197b623932334bbc98768f2eaaf5f3fa.png

324352e4c3714ae687838a1c5bb39724.png

22284e6a93ad42ffb30a812f2e699298.png

可使用在多种情景下,提升层次轮廓效果、美化界面、自定义文字修改——>

根据需求修改


六、编码实现


显示完整代码

注意路径(⊙o⊙)?

o(* ̄▽ ̄*)ブ

index.html

  1. <!DOCTYPE html>
  2. <html lang="en" >
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>咖啡</title>
  6. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
  7. <link rel="stylesheet" href="./style.css">
  8. </head>
  9. <body>
  10. <!-- partial:index.partial.html -->
  11. <!-- <a href="https://twitter.com/rominamartinlib" target="_blank">
  12. <svg viewBox="328 355 335 276" xmlns="http://www.w3.org/2000/svg">
  13. <path d="
  14. M 630, 425
  15. A 195, 195 0 0 1 331, 600
  16. A 142, 142 0 0 0 428, 570
  17. A 70, 70 0 0 1 370, 523
  18. A 70, 70 0 0 0 401, 521
  19. A 70, 70 0 0 1 344, 455
  20. A 70, 70 0 0 0 372, 460
  21. A 70, 70 0 0 1 354, 370
  22. A 195, 195 0 0 0 495, 442
  23. A 67, 67 0 0 1 611, 380
  24. A 117, 117 0 0 0 654, 363
  25. A 65, 65 0 0 1 623, 401
  26. A 117, 117 0 0 0 662, 390
  27. A 65, 65 0 0 1 630, 425
  28. Z" style="fill:#3BA9EE;" />
  29. </svg>
  30. </a> -->
  31. <div class="options">
  32. <button id="americano">Americano</button>
  33. <button id="au_lait">Au lait</button>
  34. <button id="capuccino">Capuccino</button>
  35. <button id="corretto">Corretto</button>
  36. <button id="espresso">Espresso</button>
  37. <button id="latte">Latte</button>
  38. <button id="lungo">Lungo</button>
  39. <button id="macchiato">Macchiato</button>
  40. <button id="mocha">Mocha</button>
  41. <button id="ristretto">Ristretto</button>
  42. </div>
  43. <div class="container">
  44. <h1 class="coffee_name">Choose your coffee</h1>
  45. <div class="cup">
  46. <div class="filling reset">
  47. <div class="coffee">Coffee</div>
  48. <div class="water">Water</div>
  49. <div class="liquor">Liquor</div>
  50. <div class="milk">Milk</div>
  51. <div class="whipped_cream">Whipped cream</div>
  52. <div class="milk_foam">Milk foam</div>
  53. <div class="steamed_milk">Steamed milk</div>
  54. <div class="chocolate">Chocolate</div>
  55. </div>
  56. <div class="plate"></div>
  57. </div>
  58. </div>
  59. <!-- partial -->
  60. <script src="./script.js"></script>
  61. </body>
  62. </html>

style.css

  1. :root {
  2. --main-bg-color: #d6b9a4;
  3. --cup-color: #474747;
  4. --cup-width: 30vw;
  5. --cup-height: 24vw;
  6. --cup-handle-width: 5vw;
  7. --cup-handle-height: calc(2 * var(--cup-handle-width));
  8. --cup-border-width: 2vw;
  9. --cup-inside-width: calc(var(--cup-width) - var(--cup-border-width));
  10. --cup-inside-height: calc(var(--cup-height) - var(--cup-border-width));
  11. --border-width: 1vw;
  12. --main-border: var(--border-width) solid var(--cup-color);
  13. --plate-width: 25vw;
  14. --plate-height: 2vw;
  15. --coffee-bottom: 80%;
  16. --water-bottom: 0;
  17. --milk-bottom: 0;
  18. --liquor-bottom: 0;
  19. --whipped_cream-bottom: 0;
  20. --steamed_milk-bottom: 0;
  21. --milk_foam-bottom: 0;
  22. --chocolate-bottom: 0;
  23. --coffee-color: #3c302f;
  24. --water-color: #b1dce2;
  25. --milk-color: #f0ebe5;
  26. --liquor-color: #fc8626;
  27. --whipped_cream-color: #fceecb;
  28. --milk_foam-color: #fceecb;
  29. --steamed_milk-color: #ffd7b3;
  30. --chocolate-color: #391e09;
  31. }
  32. body {
  33. height: 100vh;
  34. width: 100vw;
  35. background: var(--main-bg-color);
  36. display: flex;
  37. justify-content: space-evenly;
  38. align-items: center;
  39. margin: auto;
  40. overflow: hidden;
  41. }
  42. a {
  43. position: absolute;
  44. top: 10px;
  45. left: 10px;
  46. }
  47. svg {
  48. height: 1.5rem;
  49. }
  50. .container {
  51. display: flex;
  52. flex-direction: column;
  53. align-items: center;
  54. justify-content: center;
  55. width: 70vw;
  56. }
  57. .coffee_name {
  58. color: #f1faee;
  59. text-align: center;
  60. /* width: 100%; */
  61. font-size: 4vw;
  62. }
  63. .options {
  64. display: grid;
  65. grid-gap: 1vh;
  66. grid-template-rows: repeat(10, 35px);
  67. grid-template-columns: 120px;
  68. justify-content: space-evenly;
  69. box-sizing: border-box;
  70. }
  71. .options button {
  72. -webkit-user-select: none;
  73. -moz-user-select: none;
  74. -ms-user-select: none;
  75. user-select: none;
  76. background: rgba(214, 217, 227, 0.6);
  77. outline: none;
  78. font-size: 1rem;
  79. border: 2px solid #a67a60;
  80. box-shadow: none;
  81. color: #363636;
  82. box-sizing: border-box;
  83. border-radius: 1vh;
  84. }
  85. .options button:hover {
  86. cursor: pointer;
  87. border-width: 4px;
  88. background: rgba(255, 255, 255, 0.6);
  89. }
  90. .options .selected {
  91. border-width: 4px;
  92. background: rgba(255, 255, 255, 0.8);
  93. box-sizing: border-box;
  94. }
  95. .cup {
  96. width: var(--cup-width);
  97. height: var(--cup-height);
  98. border-radius: 0 0 10vw 10vw;
  99. position: relative;
  100. background-color: var(--cup-color);
  101. z-index: 10;
  102. box-sizing: border-box;
  103. }
  104. .cup::after {
  105. content: "";
  106. position: absolute;
  107. top: 10%;
  108. left: calc(100% - 1vw);
  109. width: var(--cup-handle-width);
  110. height: var(--cup-handle-height);
  111. border: var(--main-border);
  112. border-radius: 50% 30%;
  113. }
  114. .plate {
  115. position: absolute;
  116. top: calc(100% + 1vw);
  117. left: calc((var(--cup-width) - var(--plate-width)) / 2);
  118. width: var(--plate-width);
  119. background: var(--cup-color);
  120. height: var(--plate-height);
  121. border-radius: 1vw;
  122. }
  123. .filling {
  124. position: absolute;
  125. left: calc(var(--cup-border-width) / 2);
  126. bottom: calc(var(--cup-border-width) / 2);
  127. width: var(--cup-inside-width);
  128. height: var(--cup-inside-height);
  129. overflow: hidden;
  130. border-radius: 0 0 10vw 10vw;
  131. background-color: var(--main-bg-color);
  132. bottom: 1vw;
  133. }
  134. .filling div {
  135. position: absolute;
  136. width: 100%;
  137. transition: all 1s linear;
  138. color: #817f75;
  139. display: flex;
  140. align-items: flex-start;
  141. justify-content: center;
  142. height: 0;
  143. overflow: hidden;
  144. font-size: 3vw;
  145. height: 100%;
  146. bottom: -100%;
  147. box-sizing: border-box;
  148. }
  149. .filling.reset.americano {
  150. --water-bottom: 0;
  151. --coffee-bottom: -60%;
  152. }
  153. .filling.reset.au_lait {
  154. --coffee-bottom: -50%;
  155. --milk-bottom: 0%;
  156. }
  157. .filling.reset.capuccino {
  158. --coffee-bottom: -65%;
  159. --steamed_milk-bottom: -35%;
  160. --milk_foam-bottom: 0;
  161. }
  162. .filling.reset.espresso {
  163. --coffee-bottom: -60%;
  164. }
  165. .filling.reset.latte {
  166. --coffee-bottom: -60%;
  167. --steamed_milk-bottom: -20%;
  168. --milk_foam-bottom: 0%;
  169. }
  170. .filling.reset.corretto {
  171. --coffee-bottom: -45%;
  172. --liquor-bottom: -25%;
  173. }
  174. .filling.reset.lungo {
  175. --water-bottom: 0;
  176. --coffee-bottom: -50%;
  177. }
  178. .filling.reset.macchiato {
  179. --coffee-bottom: -70%;
  180. --milk_foam-bottom: 0;
  181. }
  182. .filling.reset.mocha {
  183. --coffee-bottom: -60%;
  184. --chocolate-bottom: -40%;
  185. --steamed_milk-bottom: -20%;
  186. --whipped_cream-bottom: 0%;
  187. }
  188. .filling.reset.ristretto {
  189. --coffee-bottom: -80%;
  190. }
  191. div.chocolate {
  192. background: var(--chocolate-color);
  193. bottom: var(--chocolate-bottom);
  194. z-index: 6;
  195. }
  196. div.coffee {
  197. background: var(--coffee-color);
  198. bottom: var(--coffee-bottom);
  199. line-height: 4vw;
  200. z-index: 7;
  201. }
  202. div.liquor {
  203. background: var(--liquor-color);
  204. bottom: var(--liquor-bottom);
  205. z-index: 4;
  206. }
  207. div.milk {
  208. background: var(--milk-color);
  209. bottom: var(--milk-bottom);
  210. z-index: 2;
  211. }
  212. div.milk_foam {
  213. background: var(--milk_foam-color);
  214. bottom: var(--milk_foam-bottom);
  215. z-index: 5;
  216. }
  217. div.steamed_milk {
  218. background: var(--steamed_milk-color);
  219. bottom: var(--steamed_milk-bottom);
  220. z-index: 6;
  221. }
  222. div.water {
  223. background: var(--water-color);
  224. bottom: var(--water-bottom);
  225. }
  226. div.whipped_cream {
  227. background: var(--whipped_cream-color);
  228. bottom: var(--whipped_cream-bottom);
  229. z-index: 4;
  230. }
  231. .filling.reset {
  232. --coffee-bottom: -100%;
  233. --water-bottom: -100%;
  234. --milk-bottom: -100%;
  235. --liquor-bottom: -100%;
  236. --whipped_cream-bottom: -100%;
  237. --steamed_milk-bottom: -100%;
  238. --milk_foam-bottom: -100%;
  239. --chocolate-bottom: -100%;
  240. }

script.js

  1. const coffee_name = document.querySelector(".coffee_name");
  2. const coffee_filling = document.querySelector(".filling");
  3. const buttons = document.querySelectorAll("button");
  4. let current_element = null;
  5. const changeCoffeeType = (selected) => {
  6. if (current_element) {
  7. current_element.classList.remove("selected");
  8. coffee_filling.classList.remove(current_element.id);
  9. }
  10. current_element = selected;
  11. coffee_filling.classList.add(current_element.id);
  12. current_element.classList.add("selected");
  13. coffee_name.innerText = selected.innerText;
  14. };
  15. const setActiveType = (element) => {
  16. element.toggleClass("selected");
  17. };
  18. [...buttons].forEach((button) => {
  19. button.addEventListener("click", () => {
  20. changeCoffeeType(button);
  21. });
  22. });

七、获取源码

老规矩,先给朋友们看一下完整文件夹,

正确的文件如下图 ,复制源码的朋友们请注意了!!!

2e7c8016d2a84dfab8d23916b1651faa.png

公众号获取源码

第一步,通过微信公众号下载源码压缩包,解压并打开文件夹,即为上图样式(复制源码请注意路径及文件名)

第二步,点击 html 文件 打开即可查看


2023年第二十三期,希望得到大家的喜欢?

也是新的系列,将会持续更新,?

希望大家有好的意见或者建议,欢迎私信


以上就是本篇文章的全部内容了

~ 关注我,点赞博文~ 每天带你涨知识!

1.看到这里了就 [点赞+好评+收藏] 三连 支持下吧,你的「点赞,好评,收藏」是我创作的动力。

2.关注我 ~ 每天带你学习 :各种前端插件、3D炫酷效果、图片展示、文字效果、以及整站模板 、HTML模板 、C++、数据结构、Python程序设计、Java程序设计、爬虫等! 「在这里有好多 开发者,一起探讨 前端 开发 知识,互相学习」!

3.以上内容技术相关问题可以相互学习,可 关 注 ↓公 Z 号 获取更多源码 !

获取源码?私信?关注?点赞?收藏?

?+✏️+⭐️+?

有需要源码的小伙伴可以 关注下方微信公众号 “ Enovo开发工厂 “,回复 关键词 “ a-coffee “

发表评论

表情:
评论列表 (有 0 条评论,167人围观)

还没有评论,来说两句吧...

相关阅读