手把手教你怎么使用CSS3实现动画效果(代码分享)
之前的文章《H5篇:页面中实现动画的几种方式?(附代码)》中,带大家了解页面中实现动画的几种方式。下面本篇文章给大家介绍怎么使用CSS3来实现一个简单漂亮的动画效果,我们一起看看
复习下 css3 的动画, 都快不会写了,那会儿挺喜欢 flash 的,可惜了时代在前进。写这里就当是文档看吧
浏览器支持
Internet Explorer 10、Firefox 以及 Opera 支持 animation 属性。
Safari 和 Chrome 支持替代的 -webkit-animation 属性。
注释:Internet Explorer 9 以及更早的版本不支持 animation 属性。
定义和用法
animation属性是一个简写属性,用于设置六个动画属性:
animation-name
animation-duration
animation-timing-function animation-delay
animation-iteration-count animation-direction
语法
animation: name duration timing-function delay iteration-count direction;
值 | 描述 | 备注 |
---|---|---|
animation-timing-function | 规定动画的速度曲线 | 可取值为 linear ,ease(淡入淡出),ease-in,ease-out ,ease-in-out,cubic-bezier(n, n, n, n) |
animation-play-state | 规定动画是否正在运行或暂停。 | paused 表示暂停状态,running 表示运行状态 |
animation-name | 规定需要绑定到选择器的 keyframe 名称 | @keyframe { from {opcity:0} to {opcity:1}} |
animation-iteration-count | 规定动画应该播放的次数 | 可选值为 infinite(无限次)n(比如 5 次) |
animation-fill-mode | 动画在播放之前或之后,其动画效果是否可见。 | none(默认) / forwards(动画完成后) / backwards(在动画显示之前) / both(两者); |
animation-duration | 规定完成动画所花费的时间,以秒或毫秒计 | 必须规定否则,不执行动画 |
animation-direction | 规定是否应该轮流反向播放动画 | 默认值 normal,alternate 为动画应该轮流反向播放。左右左 |
animation-delay | 规定在动画开始之前的延迟 | 定义动画开始前等待的时间,以秒或毫秒计。默认值是 0。单位为 s |
关于keyframe的定义
Firefox支持替代的@-moz-keyframes规则;
Opera支持替代的@-o-keyframes规则;
Safari和Chrome支持替代的@-webkit-keyframes规则;
取值支持 0-100% 和from,to。
@keyframes move { 0% { top: 0px; left: 0px; } 25% { top: 200px; left: 200px; } 50% { top: 100px; left: 100px; } 75% { top: 200px; left: 200px; } 100% { top: 0px; left: 0px; } } @keyframes move { from { top: 0px; left: 0px; } to { top: 0px; left: 100px; } }
demo 写了一个例子,地球绕太阳转
以下是代码
<!-- html 部分 --> <div style="width:700px; "> <div class="t"> <div class="t1"></div> </div> </div>
/* css 部分 */ @keyframes t { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } @-webkit-keyframes t { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } .t { height: 500px; width: 500px; position: relative; border-radius: 50%; transform: scale(.8); border: 1px solid #dedede; &::before { content: ""; width: 50px; height: 50px; background: radial-gradient(72px, #f00, #ff0, #080); border-radius: 50%; position: absolute; left: 50%; top: 50%; margin-top: -25px; margin-left: -25px; box-shadow: 0 0 37px #fcff4a; } .t1 { height: 20px; border-radius: 50%; width: 20px; margin-top: -10px; top: 50%; left: -10px; background: radial-gradient(26px, #0082ff, #184608, #003ade); position: absolute; animation: t 3s infinite linear; transform-origin: 260px center; } } </style>
还有一个 demo ,在这里https://k-ui.cn
推荐学习CSS3视频教程
以上是手把手教你怎么使用CSS3实现动画效果(代码分享)的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

纯CSS3怎么实现波浪效果?本篇文章就来给大家介绍一下使用 SVG 和 CSS 动画制作波浪效果的方法,希望对大家有所帮助!

两种方法:1、利用display属性,只需给元素添加“display:none;”样式即可。2、利用position和top属性设置元素绝对定位来隐藏元素,只需给元素添加“position:absolute;top:-9999px;”样式。

在css中,可以利用border-image属性来实现花边边框。border-image属性可以使用图片来创建边框,即给边框加上背景图片,只需要将背景图片指定为花边样式即可;语法“border-image: url(图片路径) 向内偏移值 图像边界宽度 outset 是否重复;”。

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

实现方法:1、使用“:active”选择器选中鼠标点击图片的状态;2、使用transform属性和scale()函数实现图片放大效果,语法“img:active {transform: scale(x轴放大倍数,y轴放大倍数);}”。

在css3中,可以利用“animation-timing-function”属性设置动画旋转速度,该属性用于指定动画将如何完成一个周期,设置动画的速度曲线,语法为“元素{animation-timing-function:速度属性值;}”。

css3中的动画效果有变形;可以利用“animation:动画属性 @keyframes ..{..{transform:变形属性}}”实现变形动画效果,animation属性用于设置动画样式,transform属性用于设置变形样式。
