文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

通过CSS实现逼真水滴动效

lzzyok小精灵

lzzyok小精灵

2024-04-02 17:21

关注

哈喽哈喽!CSS真的好好玩啊,哈哈,反正我是爱了,空闲写着玩。画画不好的我乐了,下面就是一个用CSS3动画完成的模仿水珠的动效,其中主要就是会使用CSS设置阴影效果以及@keyframes关键帧和一些选择器的技术,快来学习吧!!!🐬

在这里插入图片描述

实现效果:就很nice
你也通过一下网址进行访问水滴点击进入

在这里插入图片描述

灵感:看到了这张图阴影高亮,这属于美术吧,哈哈,我是小菜鸡

在这里插入图片描述


这里强烈安利GitHub上一个大牛的开源:花式边框半径生成器利用这个可以使这个效果实现的事半功倍,好开始coding

1.html

很简单,只需要一个盒子就OK了


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>水滴</title>
</head>
<body>
    <div class="shui"></div>
</body>
</html>

2.CSS

注释已经写在代码中,这里主要学习一下伪元素选择器的使用,box-shadow这个设置阴影的属性,关键帧 @keyframes以及关键帧的使用 animation,和 border-radius: 30% 70% 70% 30% / 30% 35% 65% 70%;这个属性的使用


		
        *{
            margin: 0;
            padding: 0;
        }
        
        body{
            background-color: rgba(40, 134, 241, 0.925);
        }
        
        .shui{
            width: 400px;
            height: 400px;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            
            
            box-sizing: border-box;
            
            border-radius: 30% 70% 70% 30% / 30% 35% 65% 70%;
            
            box-shadow: inset 10px 20px 30px rgba(0, 0, 0, 0.5), 10px 10px 20px rgba(0, 0, 0, 0.3), 15px 15px 30px rgba(0, 0, 0, 0.05), 
            inset -10px -10px 15px rgba(255, 255, 254, 0.83);
            
            animation: watermove 9s linear infinite;
        }
        
        .shui::after{
            content: "";
            position: absolute;
            width: 35px;
            height: 35px;
            background: rgba(255, 255, 255, 0.82);
            border-radius: 50%;
            left: 60px;
            top: 80px;
            
            animation: watermove 4s linear infinite;
        }
        
        .shui::before{
            content: "";
            position: absolute;
            width: 20px;
            height: 20px;
            background: rgba(255, 255, 255, 0.82);
            border-radius: 50%;
            left: 120px;
            top: 55px;
            
            animation: watermove 4s linear infinite;
        }
        
        @keyframes watermove{  
            20%{
                border-radius: 30% 70% 53% 47% / 28% 44% 56% 72%;
            }
           
            40%{
                border-radius: 30% 70% 39% 61% / 34% 39% 61% 66%;
            }
           
            60%{
                border-radius: 25% 75% 45% 55% / 40% 55% 45% 60%;
            }
           
            80%{
                border-radius: 28% 72% 31% 69% / 32% 39% 61% 68%;
            }
        }

3.完整代码


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>水滴</title>
    <style>
        
        *{
            margin: 0;
            padding: 0;
        }
        
        body{
            background-color: rgba(40, 134, 241, 0.925);
        }
        
        .shui{
            width: 400px;
            height: 400px;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            
            
            box-sizing: border-box;
            
            border-radius: 30% 70% 70% 30% / 30% 35% 65% 70%;
            
            box-shadow: inset 10px 20px 30px rgba(0, 0, 0, 0.5), 10px 10px 20px rgba(0, 0, 0, 0.3), 15px 15px 30px rgba(0, 0, 0, 0.05), 
            inset -10px -10px 15px rgba(255, 255, 254, 0.83);
            
            animation: watermove 9s linear infinite;
        }
        
        .shui::after{
            content: "";
            position: absolute;
            width: 35px;
            height: 35px;
            background: rgba(255, 255, 255, 0.82);
            border-radius: 50%;
            left: 60px;
            top: 80px;
            
            animation: watermove 4s linear infinite;
        }
        
        .shui::before{
            content: "";
            position: absolute;
            width: 20px;
            height: 20px;
            background: rgba(255, 255, 255, 0.82);
            border-radius: 50%;
            left: 120px;
            top: 55px;
            
            animation: watermove 4s linear infinite;
        }
        
        @keyframes watermove{  
            20%{
                border-radius: 30% 70% 53% 47% / 28% 44% 56% 72%;
            }
           
            40%{
                border-radius: 30% 70% 39% 61% / 34% 39% 61% 66%;
            }
           
            60%{
                border-radius: 25% 75% 45% 55% / 40% 55% 45% 60%;
            }
           
            80%{
                border-radius: 28% 72% 31% 69% / 32% 39% 61% 68%;
            }
        }

    </style>
</head>
<body>
    <div class="shui"></div>
</body>
</html>

OK,简简单单,快快乐乐,欢迎交流探讨,白白了你

到此这篇关于通过CSS实现逼真水滴动效的文章就介绍到这了,更多相关CSS实现水滴效果内容请搜索编程学习网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程学习网!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     676人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     305人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     262人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     366人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     174人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-前端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯