千家信息网

怎么用纯CSS实现接扎啤的特效

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,这篇文章主要介绍了怎么用纯CSS实现接扎啤的特效,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。代码解读定义dom,容器中包含一个表示酒
千家信息网最后更新 2026年11月02日怎么用纯CSS实现接扎啤的特效

这篇文章主要介绍了怎么用纯CSS实现接扎啤的特效,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

  代码解读

  定义dom,容器中包含一个表示酒桶的.keg元素和表示啤酒杯的.glass元素。酒桶有2个子元素,.handle表示把手,.pipe表示出水管,酒杯有1个表示啤酒的子元素.beer:

  

  

  

  

  

  

  

  

  

  居中显示:

  body{

  margin:0;

  height:100vh;

  display:flex;

  justify-content:center;

  background:linear-gradient(

  lightslategray300px,

  #333300px

  );

  }

  定义容器尺寸和伪元素的共有属性:

  .container{

  width:700px;

  height:300px;

  position:relative;

  }

  .container*::before,

  .container*::after{

  content:'';

  position:absolute;

  }

  画出酒桶:

  .keg{

  position:absolute;

  width:90px;

  height:200px;

  background:linear-gradient(

  toright,

  #77770px,

  #55570px

  );

  bottom:0;

  left:310px;

  }

  画出出水管和它的支架:

  .keg.pipe{

  position:absolute;

  width:10px;

  height:40px;

  background-color:#ccc;

  top:33px;

  left:10px;

  }

  .keg.pipe::before{

  width:40px;

  height:20px;

  background:

  radial-gradient(

  circleat10px10px,

  #eee7px,

  #ccc7px,#ccc10px,

  transparent10px

  ),

  linear-gradient(

  #ccc50%,

  #99950%

  );

  border-radius:10px;

  top:-2px;

  left:-5px;

  }

  画出把手:

  .keg.handle{

  position:absolute;

  border-style:solid;

  border-width:50px10px010px;

  border-color:blacktransparenttransparenttransparent;

  top:-10px;

  left:5px;

  }

  .keg.handle::before{

  width:20px;

  height:10px;

  background-color:#ccc;

  top:-60px;

  left:-10px;

  border-radius:5px5px00;

  }

  .keg.handle::after{

  width:10px;

  height:20px;

  background-color:#ccc;

  top:-20px;

  left:-5px;

  }

  画出酒杯:

  .glass{

  position:absolute;

  width:70px;

  height:100px;

  color:rgba(255,255,255,0.3);

  background-color:currentColor;

  bottom:0;

  left:300px;

  border-radius:5px;

  }

  .glass::before{

  width:50px;

  height:40px;

  border:10pxsolid;

  top:20px;

  right:-20px;

  border-radius:040%40%0;

  clip-path:inset(00072%);

  }

  画出杯中的啤酒和泡沫:

  .beer{

  position:absolute;

  width:60px;

  height:80px;

  background-color:rgba(255,206,84,0.8);

  bottom:15px;

  left:5px;

  border-radius:005px5px;

  border-top:solidrgba(255,206,84,0.8);

  }

  .beer::before{

  width:inherit;

  height:15px;

  background-color:#eee;

  top:-15px;

  border-radius:5px5px00;

  }

  接下来制作动画。

  增加酒杯把手被压下的动画效果:

  .keg.handle{

  transform-origin:center50px;

  animation:handle5sinfinite;

  }

  @keyframeshandle{

  10%,60%{

  transform:rotate(0deg);

  }

  20%,50%{

  transform:rotate(-90deg);

  }

  }

  增加啤酒被斟满的动画效果:

  .beer{

  animation:fillup5sinfinite;

  }

  @keyframesfillup{

  0%,20%{

  height:0px;

  border-width:0px;

  }

  40%{

  height:40px;

  }

  80%,100%{

  height:80px;

  border-width:5px;

  }

  }

  增加啤酒泡沫泛起的动画效果:

  .beer::before{

  animation:

  wave0.5sinfinitealternate,

  fillup-foam5slinearinfinite;

  }

  @keyframesfillup-foam{

  0%,20%{

  top:0;

  height:0;

  }

  60%,100%{

  top:-15px;

  height:15px;

  }

  }

  @keyframeswave{

  from{

  transform:skewY(-3deg);

  }

  to{

  transform:skewY(3deg);

  }

  }

  增加啤酒从出水口流出的效果:

  .keg.pipe::after{

  width:10px;

  background-color:rgba(255,206,84,0.5);

  animation:flow5sinfinite;

  }

  @keyframesflow{

  0%,15%{

  top:40px;

  height:0;

  }

  20%{

  height:115px;

  }

  40%{

  height:75px;

  }

  55%{

  top:40px;

  height:50px;

  }

  60%,100%{

  top:80px;

  height:0;

  }

  }

  最后,增加酒杯滑动的效果:

  .glass{

  animation:slide5seaseinfinite;

  }

  @keyframesslide{

  0%{

  left:0;

  filter:opacity(0);

  }

  20%,80%{

  left:300px;

  filter:opacity(1);

  }

  100%{

  left:600px;

  filter:opacity(0);

  }

  }

感谢你能够认真阅读完这篇文章,希望小编分享的"怎么用纯CSS实现接扎啤的特效"这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!

很赞哦!
啤酒 元素 效果 动画 篇文章 酒杯 把手 酒桶 扎啤 特效 容器 泡沫 接下来 个子 代码 价值 兴趣 出水口 出水管 同时 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网公司 科技公司 互联网 卓越科技 四川狮子座互联网科技 美国互联网前沿科技 湖南洣水互联网科技有限公司扣款 创业天下互联网科技有限公司 全球顶尖互联网科技公司 南平创想时代互联网科技有限公司 厦门千工互联网科技有限公司 互联网科技商业 互联网科技人工智能实验室 科技类公司包括互联网吗 华中科技大学互联网的牛人 启辰互联网科技 2021世界互联网领先科技成果发布 张家口科技产业互联网平台 求路客互联网科技电话 美国五大互联网科技公司市值多少 三亚科技创新互联网基地 互联网科技企业文化 喔噻互联网科技有限公司 互联网科技未来 科技类互联网 互联网科技革命什么开始 知域互联网科技有限公司大骗子 宜昌元轩互联网科技有限公司 互联网科技融合创新 有人说阿里系是互联网科技企业 萌小萌互联网科技河南有限公司 银川新华互联网科技学校原画
0