CSS中动画的基础知识是什么,怎样实现奔跑小熊的动画
Admin 2022-09-21 群英技术资讯 1370 次浏览
这篇文章给大家介绍了“CSS中动画的基础知识是什么,怎样实现奔跑小熊的动画”的相关知识,讲解详细,步骤过程清晰,有一定的借鉴学习价值,因此分享给大家做个参考,感兴趣的朋友接下来一起跟随小编看看吧。动画就是一帧又一帧图片,按顺序展现在人的眼前,但是由于人的视觉反应不过来就会产生图画动起来的效果。
动画声明需要使用@keyframes name,后面的name是人为定义的动画名称
@keyframes move {
0% {
transform: translate(0, 0);
}
25% {
transform: translate(1000px, 0px);
}
50% {
transform: translate(1000px, 400px);
}
75% {
transform: translate(0px, 400px);
}
100% {
transform: translate(0, 0);
}
}
在以上代码中,{}内包含的就是动画的动作,每一个完整的动画都会一定的时间,其中
意思是每达到时间的百分之多少就向某状态进行转变。
<!--
动画属性有很多种
div {
动画的名称(必须要有)
animation-name: move;
动画的运动曲线(linear是匀速stept()是分步)
animation-timing-function: linear;
动画的运动时间
animation-duration: 3s;
动画的运动次数(infinite是无限循环)
animation-iteration-count: infinite;
动画的开始时间
animation-delay: 1s;
动画是否逆序播放
animation-direction: alternate;
}
动画播放期间触碰暂停
div:hover {
animation-play-state: paused;
}
动画播放完毕是否回到初始位置
animation-fill-mode: forwards;(不回到初始位置)
backwards(回到初始位置)
-->
<!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>Document</title>
<style>
@keyframes move {
0% {
width: 0;
height: 0;
}
100% {
width: 300px;
height: 300px;
}
}
div {
margin: 200px auto;
/* width: 300px;
height: 300px; */
background-color: darkviolet;
animation-name: move;
animation-timing-function: linear;
animation-duration: .4s;
animation-iteration-count: infinite;
animation-delay: 1s;
animation-direction: alternate;
animation-fill-mode: forwards;
}
div:hover {
animation-play-state: paused;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
<!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>Document</title>
<!--
每一帧图片连接到一块就组成了一个动画
-->
<style>
body {
position: relative;
background-color: gray;
}
@keyframes bear {
0% {
background-position: 0px 0px;
}
100% {
background-position: -1600px 0px;
}
}
@keyframes bgcmove {
0% {
left: 0;
}
100% {
left: 50%;
transform: translateX(-50%);
}
}
@keyframes mountains {
0% {
background-position: 0px 0px;
}
100% {
background-position: -3840px 0px;
}
}
.mountain {
/*
这里定位定到父类的底部,得不到想要的结果
*/
position: absolute;
bottom: -601px;
width: 100%;
height: 200px;
background-image: url(../bg1.png);
animation: mountains 8s linear infinite;
}
.nav {
position: absolute;
bottom: -601px;
width: 200px;
height: 100px;
background-image: url(../bear.png);
/* background-size: 100% 100%; */
/* animation: name duration timing-function delay iteration-count direction fill-mode; */
/* 值得注意的是steps与linear不可以混合使用 */
animation: bear .8s steps(8) infinite, bgcmove 3s linear forwards;
}
</style>
</head>
<body>
<div class="mountain"></div>
<div class="nav"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body {
background-color: #333;
}
.map {
position: relative;
width: 747px;
height: 616px;
background: url(../map.png) no-repeat;
margin: 0 auto;
}
.city {
position: absolute;
top: 227px;
right: 193px;
color: #fff;
}
.tb {
top: 500px;
right: 80px;
}
.dotted {
width: 8px;
height: 8px;
background-color: #09f;
border-radius: 50%;
}
.city div[class^="pulse"] {
/* 保证我们小波纹在父盒子里面水平垂直居中 放大之后就会中心向四周发散 */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 8px;
height: 8px;
box-shadow: 0 0 12px #009dfd;
border-radius: 50%;
animation: pulse 1.2s linear infinite;
}
.city div.pulse2 {
animation-delay: 0.4s;
}
.city div.pulse3 {
animation-delay: 0.8s;
}
@keyframes pulse {
0% {}
70% {
/* transform: scale(5); 我们不要用scale 因为他会让 阴影变大*/
width: 40px;
height: 40px;
opacity: 1;
}
100% {
width: 70px;
height: 70px;
opacity: 0;
}
}
</style>
</head>
<body>
<div class="map">
<div class="city">
<div class="dotted"></div>
<div class="pulse1"></div>
<div class="pulse2"></div>
<div class="pulse3"></div>
</div>
<div class="city tb">
<div class="dotted"></div>
<div class="pulse1"></div>
<div class="pulse2"></div>
<div class="pulse3"></div>
</div>
</div>
</body>
</html>
到此,关于“CSS中动画的基础知识是什么,怎样实现奔跑小熊的动画”的学习就结束了,希望能够解决大家的疑惑,另外大家动手实践也很重要,对大家加深理解和学习很有帮助。如果想要学习更多的相关知识,欢迎关注群英网络资讯站,小编每天都会给大家分享实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章主要介绍了html5实现可拖拽移动的悬浮图标的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
这篇文章主要介绍了使用CSS制作立体导航栏的相关资料,需要的朋友可以参考下
这篇文章主要给大家分享如何用CSS3来实现红包抖动效果,小编觉得挺有趣,因此给大家分享一下实现代码,感兴趣的朋友可以参考参考,下面我们就一起来看看。
这篇文章主要介绍了HTML5 canvas实现的静态循环滚动播放弹幕,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
canvas与svg都是可以在浏览器上创建图形,因此,在html5中感觉canvas和svg很相似,但是实际上canvas与svg有着根本的区别。下面php中文网通过比较canvas和svg之间的不同来给大家总结了关于canvas与svg的区别。一起来看一看吧。
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008