快六一啦,学习CSS3实现一个冰淇淋动画特效

news2024/10/7 16:22:27

快六一啦,小时候顶多吃个小冰棍,或者是那种小冰袋,现在的小朋友真是好,动不动就能吃到冰淇淋,今天用CSS3实现一个冰淇淋的动画特效吧

 

目录

实现思路

桶身的实现

冰淇淋身体的实现

五彩颗粒的实现

HTML源码

CSS3源码

最后


实现思路

  • 本文采用多DOM的方式进行布局,冰淇淋桶身通过border-radius进行特殊区域进行圆润处理;
  • 眼部比较容易理解,先做大的border-radius圆角形状,然后内部做小的白色圆角处理,并且进行定位;通过animation动画,使眼睛可以左右移动;
  • 嘴角做半圆处理,然后再通过rotateZ角度旋转,变为卡通可爱形;
  • 然后是顶部分三部分处理,包括右上角的樱桃部分;
  • 最后是五彩颗粒,采用定位的方式,因为原本我们采用的是DIV元素,所以需要使用一定的圆角处理;

桶身的实现

桶身使用.base类,对widthheight做固定,使用position做定位,所以需要z-index的属性加入,需要一定的圆角,又要使用border-radius做处理;

底部为了模拟放在桌子表面上,需要有一个放置的阴影效果,这里使用filter的属性,并控制其blur属性值,

眼睛就是大的DIV套小的DIV,然后采用position进行定位,分别以border-radius做圆角处理,这里需要一个animation动画,使其左右转动,注意,分为左右两只可爱小眼睛

嘴角因为是DIV元素,而且首先做了上半圆的处理,然后再使用rotateZ(180deg)将其旋转即可;

部分CSS3代码如下:

.eye{
    width: 4vmax;
    height: 4vmax;
    border-radius: 50%;
    position: absolute;
    background: #472a1c;
    top: 19vmax;
    z-index: 110;
}

.eye::before{
    content: '';
    position: absolute;
    top: .75vmax;
    left: .75vmax;
    width: 1.15vmax;
    height: 1.15vmax;
    border-radius: 50%;
    background: white;
    animation: 4s eye infinite ;

}
.eye::after{
    content: '';
    position: absolute;
    top: 2.5vmax;
    left: 1vmax;
    width: .5vmax;
    height: .5vmax;
    border-radius: 50%;
    background: white;
    animation: 4s eye infinite ;

}
.eye-l{ left: 8.8vmax; }
.eye-r{ left: 17.5vmax; }

 

冰淇淋身体的实现

身体部分采用上中下3个DOM元素做分层处理,分别添加.top__item类,因为冰淇淋被挤压到桶身后呈圆形,所以border-radius真是一个神奇的属性

然后再通过::before::after伪类进行阴影部分的元素定位与布局,再配合linear-gradient使特殊部位进行阴影效果,使效果更逼真;

顶部樱桃部分位于最顶部的.top_item类中,但樱桃并非border-radius:50%那样的圆角,而是稍微有一点非圆角,部分CSS3代码如下

.top__item:nth-of-type(3)::before{
    content: '';
    position: absolute;
    width: 4vmax;
    height: 4vmax;
    right: 0;
    top: 0vmax;
    border-radius: 50% / 60%;
    background: #e30b5d;
    transform: rotateZ(-10deg);
}

 

五彩颗粒的实现

五彩颗粒重点在于定位和方位旋转效果,这里使用了absolute定位,并且需要z-index的层级比其他元素要高,然后再分别进行top值和left值的定位,并采用rotateZ的旋转属性,使每个五彩颗粒角度方位不同,但其实看这个冰淇淋也就是两种角度,而且为了更吸引小朋友,需要做成不同颜色的,这就需要不同的background属性值,这个比较简单,部分CSS3代码如下

.chips{
    width: 2vmax;
    height: .5vmax;
    position: absolute;
    top: 10vmax;
    left: 8vmax;

    border-radius: 50%;
    transform: rotateZ(35deg);
    z-index: 200;
}
.chips:nth-of-type(2){
    top: 8vmax;
    left: 12vmax;
}

到这里就算讲解完成了,但讲N遍也不如拿到代码自己看一看,改一改源码玩一玩,下面给出源码

HTML源码

<body>
<div class="main">
	<div class="base"></div>
	<div class="sdw"></div>
	
	<div class="eye eye-l"></div>
	<div class="eye eye-r"></div>
	<div class="shadow shadow-l"></div>
	<div class="shadow shadow-r"></div>
	<div class="mouth"></div>
	
	<div class="top">
		<div class="top__item"></div>
		<div class="top__item"></div>
		<div class="top__item"></div>
	</div>
	
	<div class="colors">
		<div class="chips chips--blue"></div>
		<div class="chips chips--pink chips--rotate"></div>
		<div class="chips chips--green"></div>
		<div class="chips chips--blue chips--rotate"></div>
		<div class="chips chips--pink"></div>
		<div class="chips chips--green chips--rotate"></div>
		<div class="chips chips--blue"></div>
	</div>
</div>

CSS3源码

<style>
	*,
*::before,
*::after{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body{
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100vh;
    background: #FFD275;
    color: white;
    overflow: hidden;
    font-family: 'Montserrat', sans-serif;
    position: relative;

}
a{
    font-family: sans-serif;
    font-size: 12px;
    font-weight: normal;
    text-decoration: none;
    letter-spacing: 0;
    cursor: pointer;
    color: #00b1b7;
}
.particles{
    width: 100%;
    height: 100vh;
    position: absolute;
    z-index: 1;
}

.main{
    height: 30vmax;
    width: 30vmax;
    position: relative;
    animation: 2s jump ease-out infinite alternate;
    z-index: 10;
}
.base{
    position: absolute;
    width: 18vmax;
    bottom: 4vmax;
    left: 6vmax;

    border-top: 10vmax solid #ff87a4;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    border-left: 3vmax solid transparent;
    border-right: 3vmax solid transparent;
    border-bottom: none;
    z-index: 90;

}
.base::after{
    content: '';
    position: absolute;
    width: 12vmax;
    height: 4vmax;
    background: linear-gradient(to bottom, #ff87a4 60%, #e3748f);
    bottom: -1.65vmax;
    border-radius: 50%;
}

.eye{
    width: 4vmax;
    height: 4vmax;
    border-radius: 50%;
    position: absolute;
    background: #472a1c;
    top: 19vmax;
    z-index: 110;
}

.eye::before{
    content: '';
    position: absolute;
    top: .75vmax;
    left: .75vmax;
    width: 1.15vmax;
    height: 1.15vmax;
    border-radius: 50%;
    background: white;
    animation: 4s eye infinite ;

}
.eye::after{
    content: '';
    position: absolute;
    top: 2.5vmax;
    left: 1vmax;
    width: .5vmax;
    height: .5vmax;
    border-radius: 50%;
    background: white;
    animation: 4s eye infinite ;

}
.eye-l{ left: 8.8vmax; }
.eye-r{ left: 17.5vmax; }

.shadow{
    position: absolute;
    width: 2vmax;
    height: 1vmax;
    bottom: 6.5vmax;
    z-index: 109;
    border-radius: 50%;
    background: #ff2a7b;
    animation: .1s shake infinite;

}
.shadow-l{ left: 8.4vmax; }
.shadow-r{ left: 19.5vmax; }

.mouth{
    position: absolute;
    top: 23vmax;
    left: calc(15vmax - 1.5vmax);

    border-top-left-radius: 1.5vmax;
    border-top-right-radius: 1.5vmax;
    border: 1.5vmax solid #ff2a7b;
    transform: rotateZ(180deg);

    z-index: 110;
    animation: 2s mouth infinite alternate;

}


.top{
    position: absolute;
    width: 22vmax;
    height: 15vmax;
    bottom: 12vmax;
    left: 4vmax;
}
.top__item:nth-of-type(1){
    position: absolute;
    width: 100%;
    height: 8vmax;
    border-radius: 5vmax;
    bottom: 0;
    z-index: 100;
    background: #f2e7e8;

}
.top__item:nth-of-type(1)::after{
    content: '';
    position: absolute;
    width: 10vmax;
    height: 10vmax;
    right: -.5vmax;
    top: -2vmax;
    border-radius: 50%;
    background: #f2e7e8;
    background: linear-gradient(120deg, rgba(242, 231, 232, 1) 40%, #d6c6c8);

}
.top__item:nth-of-type(1)::before{
    content: '';
    position: absolute;
    width: 18vmax;
    height: 3vmax;
    left: 2vmax;
    bottom: -.8vmax;
    border-radius: 50%;
    background: linear-gradient(to bottom, #f2e7e8 30%, #d6c6c8);

}
.top__item:nth-of-type(2){
    position: absolute;
    width: 16vmax;
    height:5vmax;
    bottom: 6vmax;
    left: 3vmax;
    border-radius: 5vmax;
    z-index: 80;
    background: #f2e7e8;
}
.top__item:nth-of-type(2)::after{
    content: '';
    position: absolute;
    width: 4vmax;
    height: 4vmax;
    right: 0;
    top: -1vmax;
    border-radius: 50%;
    background: #f2e7e8;
}
.top__item:nth-of-type(3){
    position: absolute;
    width: 12vmax;
    height: 10vmax;
    left: 5vmax;
    border-radius: 50%;
    top: 0;
    z-index: 70;
    background: #f2e7e8;
}
.top__item:nth-of-type(3)::before{
    content: '';
    position: absolute;
    width: 4vmax;
    height: 4vmax;
    right: 0;
    top: 0vmax;
    border-radius: 50% / 60%;
    background: #e30b5d;
    transform: rotateZ(-10deg);
}
.top__item:nth-of-type(3)::after{
    content: '';
    position: absolute;
    width: 1vmax;
    height: 1vmax;
    right: 1vmax;
    top: .75vmax;
    border-radius: 50%;
    background: white;
    opacity: .4;
}


.chips{
    width: 2vmax;
    height: .5vmax;
    position: absolute;
    top: 10vmax;
    left: 8vmax;

    border-radius: 50%;
    transform: rotateZ(35deg);
    z-index: 200;
}
.chips:nth-of-type(2){
    top: 8vmax;
    left: 12vmax;
}
.chips:nth-of-type(3){
    top: 4vmax;
    left: 14vmax;
}
.chips:nth-of-type(4){
    top: 14vmax;
    left: 14vmax;
}
.chips:nth-of-type(5){
    top: 15vmax;
    left: 18vmax;
}
.chips:nth-of-type(6){
    top: 9vmax;
    left: 20vmax;
}
.chips:nth-of-type(7){
    top: 15vmax;
    left: 6vmax;
}

.chips--rotate{ transform: rotateZ(-35deg); }
.chips--blue{ background: #00b1b7; }
.chips--pink{ background: #ff2c7c; }
.chips--green{ background: #00df4a; }


.sdw{
    width: 12vmax;
    height: 4vmax;
    position: absolute;
    bottom: 1.5vmax;
    left: calc(50% - 6vmax);

    background: black;
    border-radius: 50%;
    filter: blur(3px);
    animation: 2s sdw ease-out infinite alternate;

}
@keyframes sdw {
    0%, 90%{
        opacity: .3;
        transform: translateY(0vmax) scale(.98);
    }
    100%{
        transform: translateY(5vmax) scale(.95);
        opacity: .1;
    }
}

@keyframes eye {
    0%, 45%{ transform: translateX(0vmax);}
    50%, 95%{ transform: translateX(1.25vmax);}
}
@keyframes mouth {
    0%, 80%{
        border: 1.5vmax solid #ff2a7b;
        border-bottom: 0;
    }
    100%{
        border: 1.5vmax solid #ff2a7b;
    }
}

@keyframes shake {
    0%{ transform: translateY(-1px); }
    100%{ transform: translateY(1px);}
}
@keyframes jump {
    0%, 90%{
        transform: translateY(2vmax) scale(1);
    }
    100%{
        transform: translateY(-3vmax) scale(.95);
    }
}
@keyframes move {
    0%{
        transform: translateY(0) rotateZ(35deg);
        opacity: 0;
    }
    10% ,90%{
        opacity: .35;
    }
    100%{
        transform: translateY(35vmax) rotateZ(-35deg);
        opacity: 0;
    }
}

</style>

最后

最后,希望不管是大人还是小朋友们,都可以渡过一个快乐的六一儿童节,即便自己不是小孩子了,也奖励自己一个六一小礼物吧

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/587822.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

17 张程序员专属壁纸推荐

1、三思后再写代码&#xff01;&#xff01;&#xff01; 2、从世界上搜索喜欢你的人&#xff01;&#xff01;&#xff01; 3、代码没写完&#xff0c;哪里有脸睡觉&#xff01;&#xff01;&#xff01; 4、程序员的 Home 键&#xff01;&#xff01;&#xff01; 5、编程是…

【完整项目开发】Springboot+vue教学材料管理系统定制开发

Springbootvue 的专业建建设材料管理系统。 **大家好&#xff0c;今天分享最近做的一套系统。**起因源于小伙伴的需求 文末有的获取方式&#xff0c;如需定制系统&#xff0c;需求发来&#xff0c;我为你分忧&#xff0c;搞起 一、 项目介绍 基于各个专业&#xff0c;对教…

代码随想录算法训练营day56 | 583. 两个字符串的删除操作,72. 编辑距离,编辑距离总结篇

代码随想录算法训练营day56 | 583. 两个字符串的删除操作&#xff0c;72. 编辑距离&#xff0c;编辑距离总结篇 583. 两个字符串的删除操作解法一&#xff1a;动态规划解法二&#xff1a;计算最长公共子序列&#xff0c;然后用数组长度减掉子序列长度 72. 编辑距离解法一&#…

界面组件DevExpress ASP.NET Core v22.2 - UI组件升级

DevExpress ASP.NET Core Controls使用强大的混合方法&#xff0c;结合现代企业Web开发工具所期望的所有功能。该套件通过ASP.NET Razor标记和服务器端ASP.NET Core Web API的生产力和简便性&#xff0c;提供客户端JavaScript的性能和灵活性。ThemeBuilder工具和集成的Material…

【操作系统】01.操作系统概论

操作系统的发展历史 未配置操作系统 手工操作阶段 用户独占全机&#xff0c;人机速度矛盾导致系统资源利用率低 脱机输入输出方式 为了缓解主机cpu和IO设备之间速度不匹配的矛盾&#xff0c;出现了脱机IO技术 在外围机的控制下&#xff0c;通过输入设备&#xff0c;将数据输…

Spring事务和事务的传播机制

一、为什么需要事务 1.1事务定义 将一组操作封装成一个执行单元&#xff0c;要么全部成功要么全部失败。 1.2为什么要用事物 例如转账分为两个操作&#xff1a; 第⼀步操作&#xff1a;A 账户 -100 元。第⼆步操作&#xff1a;B 账户 100 元。 如果没有事务&#xff0c;第…

脱岗监测预警系统 yolov5

脱岗监测预警系统可以通过pythonyolov5网络模型深度学习算法&#xff0c;脱岗监测预警算法对现场人员岗位进行实时监测&#xff0c;自动识别是否存在脱岗行为&#xff0c;并及时发出警报。Yolo意思是You Only Look Once&#xff0c;它并没有真正的去掉候选区域&#xff0c;而是…

2023安卓逆向 -- 抓包环境设置(Charles+Postern)

一、下载Charles并设置代理 1、下载地址&#xff0c;一路下一步即可安装 https://www.charlesproxy.com/ 2、代理设置&#xff0c;抓取所有ip及所有端口的数据包&#xff0c;点击Proxy&#xff0c;选择SSL Proxying Settings 3、点击Add&#xff0c;Host和Port都填写*&#x…

chatgpt赋能python:Python中的升序降序sort解析

Python中的升序降序sort解析 在 Python 开发中&#xff0c;sort 方法是非常常用的方法&#xff0c;它可以对包含数字或字符串的列表进行排序&#xff0c;其中有两种排序方式&#xff0c;分别是升序和降序。本篇文章将会深入探讨 Python 中的 sort 方法&#xff0c;着重介绍升序…

【回顾经典AI神作】卷积神经网络CNN架构系列:LeNet,AlexNet,VGG,GoogLeNet,ResNet

卷积神经网络(CNN或ConvNet)是一种特殊的多层神经网络,旨在以最少的预处理直接从像素图像中识别视觉模式。ImageNet项目是一个大型视觉数据库,设计用于视觉对象识别软件研究。ImageNet 项目举办年度软件竞赛,即 ImageNet 大规模视觉识别挑战赛 (ILSVRC),软件程序竞相正…

企业客户管理难题都有哪些?CRM系统如何解决?

CRM系统在客户管理中的重要性不言而喻&#xff0c;它可以帮助企业提高销售效率&#xff0c;优化客户体验和忠诚度&#xff0c;增加市场份额和利润。那么&#xff0c;CRM客户管理系统如何解决大客户管理难题? 企业大客户管理难题都有哪些&#xff1a; 1、需求十分多变 大客户…

第二节 Python分支结构

文章目录 一&#xff0c;分支结构1.1 概述1.2 语法格式1.2.1 单分支语法结构1.2.2 多分支语法结构1.2.3 多重语法结构1.2.4 分支语句的嵌套结构 1.3 Debug调试1.4 三元运算符1.4.1 求两个数的差值 二 专项练习题2.1 计算快递包裹重量2.2 判断奇偶数2.3 判断闰年2.4 最大的数2.5…

Win11怎么远程控制另外一台电脑?

​Win11是微软推出的一款Windows操作系统&#xff0c;它改善了视觉效果&#xff0c;并具有许多创新功能&#xff0c;例如集成的Android应用程序&#xff0c;用于游戏的Xbox技术等。如今&#xff0c;许多用户已从Win10或Win7升级到Win11。但是很多用户不知道Win11怎么远程控制另…

ArcGis系列-java发布空间表为要素服务(feature)

1,实现思路 使用java调用cmd命令执行python脚本python环境使用arcgis pro安装目录下的 \ArcGIS\Pro\bin\Python\envs\arcgispro-py3发布数据库表前需要先用创建数据库的sde文件&#xff08;创建sde文件不需要连接arcgis&#xff09;发布表时,先在本地的空项目模板中添加数据库…

界面组件Telerik UI for WPF可轻松实现直方图,让数据可视化更简单

Telerik UI for WPF拥有超过100个控件来创建美观、高性能的桌面应用程序&#xff0c;同时还能快速构建企业级办公WPF应用程序。UI for WPF支持MVVM、触摸等&#xff0c;创建的应用程序可靠且结构良好&#xff0c;非常容易维护&#xff0c;其直观的API将无缝地集成Visual Studio…

word如何设置页码?教您快速掌握!

案例&#xff1a;论文排版时&#xff0c;需要对页码进行编号&#xff0c;但我不知道怎么操作。我想如何快速设置word页码&#xff0c;有没有小伙伴可以分享一下方法&#xff1f; word是一款广泛使用的文字处理软件&#xff0c;许多人在撰写论文、报告或其他文档时都需要对页面…

StableDiffusion教程(3) - 模型安装

StableDiffusion模型安装 1. 搜索模型 打开C站或者LibLibAI模型站下载模型 C站地址&#xff1a;https://civitai.com/ LibLibAI模型站地址&#xff1a;LiblibAi - 中国领先原创AI模型分享社区 2. 下载模型 在模型详情页面&#xff0c;点击下载即可下载模型 3. 把模型放进S…

《A New General Type-2 Fuzzy Predictive Scheme for PID Tuning》翻译,2021年

《一种新的用于PID整定的通用2型模糊预测方案》 摘要 PID控制器在各种工业应用中被广泛使用。但是&#xff0c;在许多有噪音的问题中&#xff0c;需要强有力的方法来优化PID参数。在本文中&#xff0c;介绍了一种通过模型预测控制和广义 2 型模糊逻辑系统调整比例-积分-微分参数…

一步一步的指导在自定义数据集上训练 YOLO NAS

本教程将一步一步指导实验 YOLO-NAS 的进行完整的数据集训练。 YOLO-NAS是目前最新的YOLO物体检测模型。从一开始,它就在准确性方面击败了所有其他 YOLO 模型。与之前的 YOLO 模型相比,经过预训练的 YOLO-NAS 模型可以更准确地检测到更多的对象。但是我们如何在自定义数据集…

MySQL 条件判断函数

文章目录 条件判断函数if()函数ifnull() 函数case() 函数1. 成功匹配其中一条 when 分支3. 所有 when 分支匹配失败&#xff0c;进入 else 默认分支。 条件判断函数 关于条件判断函数&#xff0c;主要介绍以下三种&#xff1a; if()函数 if() 函数&#xff0c;其基本语法如下…