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

这篇具有很好参考价值的文章主要介绍了快六一啦,学习CSS3实现一个冰淇淋动画特效。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

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

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

 

目录

实现思路

桶身的实现

冰淇淋身体的实现

五彩颗粒的实现

HTML源码

CSS3源码

最后


快六一啦,学习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; }

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

 

冰淇淋身体的实现

身体部分采用上中下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);
}

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

 

五彩颗粒的实现

五彩颗粒重点在于定位和方位旋转效果,这里使用了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>

最后

最后,希望不管是大人还是小朋友们,都可以渡过一个快乐的六一儿童节,即便自己不是小孩子了,也奖励自己一个六一小礼物吧文章来源地址https://www.toymoban.com/news/detail-464510.html

到了这里,关于快六一啦,学习CSS3实现一个冰淇淋动画特效的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • css3+javaScript实现一个左右钟摆-摇晃的红灯笼网页特效

    css3+javaScript实现一个左右钟摆-摇晃的红灯笼网页特效!前天逛博客时无意中看见了,别人的博客顶部有一个会左右钟摆的摇晃的红灯笼,产生了想法,我也想给自己做一个,但是网上找了很多方案,都没有实现。终于在昨天晚上搜索,找到了利用css3和js一起组合的技术,实现

    2024年01月20日
    浏览(27)
  • 为你心仪的她做一个 “旋转木马“告白相册【零基础纯 CSS3 实现】

          旋转相册效果里面就不放女朋友的美照了防止虐狗 🥰🥰🥰,就用个前端技能树的图片代替哈,有需要大家自行替换。        源码我已经上传到了资源里,有会员的小伙伴直接下载即可,没有会员的小伙伴私聊我“旋转木马”也能获取(免费的),下面是源码资源的

    2024年01月16日
    浏览(29)
  • 【CSS3】使用纯CSS做一个简易轮播图(小解送书第二期)

    ✍️ 作者简介: 前端新手学习中。 💂 作者主页: 作者主页查看更多前端教学 🎓 专栏分享:css重难点教学   Node.js教学 从头开始学习   ajax学习 html css 618,清华社 IT BOOK 多得图书活动开始啦!活动时间为 2023 年 6 月 7 日至 6 月 18 日,清华社为您精选多款高分好书,涵盖了

    2024年02月11日
    浏览(24)
  • CSS3学习(一)

    CSS主要由选择器和一条或多条的声明构成。 选择器用于指定CSS样式的HTML标签,花括号里面是对应的具体样式 属性与属性值以键值对的形式出现,属性与属性之间用 分号 隔开 head里写style 【作用】选择标签使用 选择器分为基础选择器和复合选择器,基础选择器是由单个选择

    2024年02月19日
    浏览(22)
  • 前端学习——CSS3

    box-sizing resize box-shadow opacity background-origin background-clip background-size background复合属性 多背景图 边框圆角 边框外轮廓 文本阴影 文本换行 文本溢出 文本修饰 文本描边 线性渐变

    2024年02月12日
    浏览(25)
  • 儿童节快乐,基于CSS3绘制一个游乐场动效界面

    让代码创造童话,共建快乐世界。六一儿童节——这是属于孩子们的节日,也是属于我们大人的节日。让我们一起「致童真」,用代码(HTML+CSS+JS)创造出一个游乐场,让这个世界多一份快乐和惊喜! 一张图不用,纯代码制作👇 使用任意HTML编辑软件(如:Dreamweaver、HBuilde

    2024年02月07日
    浏览(24)
  • html+css3 补充学习

    1.1 strong 着重阅读,也可以理解为加粗效果 2.1 空格 2.2 一个中文宽度实体 例子 标签、类、id选择非常常用,前边的文档写过了,不在记录了 1.1 后代选择器 子标签 子子标签 子子子标签都是后代选择器 1.2 子代选择器 子代选择器只选择 下边1层 更多写法 1.3 兄弟选择器 相邻兄

    2024年01月20日
    浏览(28)
  • 我让ChatGPT用CSS3画一个皮卡丘,还是自己画的可爱

    突然想到了小时候看过的动画片《皮卡丘》,于是突然就想,ChatGPT肯定也看过,他哪有不知道的东西啊,于是就想着让他帮我画一个,他画出来之后,我笑了,这啥玩意儿啊。   目录 一、第一次尝试让ChatGPT用CSS3画皮卡丘 1. 绘制皮卡丘的耳朵: 2. 绘制皮卡丘的眼睛: 3. 

    2024年02月04日
    浏览(22)
  • 前端小白的学习之路(CSS3 三)

    提示:过渡属性transition,动画属性animation,转化属性transform,裁剪属性clip-path,倒影属性box-reflect,模糊度属性filter  目录 一、transition  二、animation  三、transform  四、clip-path   五、box-reflect  六、filter  过渡:以看见标签从一个属性变化到另一个属性值的过程。 transition-pro

    2024年03月19日
    浏览(25)
  • css3实现炫彩字体

    这个字体颜色是动态变化的,直接上代码 background-clip :背景裁剪,有哪些值自行百度; -webkit-text-fill-color :一定要加 -webkit ,文字颜色填充,效果和color差不多; 突然发现的小知识点: border: 1px solid; :以前以为不设置边框颜色,默认是黑色,结果发现是默认和字体颜色一样

    2024年02月21日
    浏览(19)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包