css怎么做水杯流动
导读:在CSS中,我们可以通过利用动画和过渡来实现让水杯流动的效果。/*首先,我们定义一个基本样式*/.cup{ width: 100px; height: 150px; border: 2px solid #999; border-ra...
在CSS中,我们可以通过利用动画和过渡来实现让水杯流动的效果。
/*首先,我们定义一个基本样式*/.cup{
width: 100px;
height: 150px;
border: 2px solid #999;
border-radius: 50%;
position: relative;
overflow: hidden;
}
.cup:before{
content: "";
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #fff;
position: absolute;
top: -10px;
left: calc(50% - 10px);
}
/*接着,我们通过动画让液体在杯中流动*/.cup .liquid{
width: 80%;
height: 45%;
background-color: blue;
position: absolute;
bottom: 0%;
left: 10%;
transform-origin: bottom;
animation: flow 2s infinite;
animation-timing-function: linear;
}
@keyframes flow{
0%{
transform: scaleY(0);
}
50%{
transform: scaleY(1);
}
100%{
transform: scaleY(0);
}
}
/*最后,我们给杯子加上过渡来让它看起来更连续*/.cup:hover .liquid{
height: 70%;
transition: height 0.3s ease-in-out;
}
这段代码简单易懂,让我们可以轻松实现一个非常酷的水杯流动效果。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: css怎么做水杯流动
本文地址: https://pptw.com/jishu/534783.html
