在设计网页时通常会加一些动画特效,吸引使用者的目光及添加与使用者的互动性。
过去制作动画时以Flash为主,CSS3也可以建立动画,不再只能用JavaScript或jQuery 才做得到了
transition-property: none|all|property;
<h1>test</h1>
h1{
height:100px;
background-color:yellow;
transition-property:color,background,height;
transition-duration:3s;
}
h1:hover{
color:red;
background-color:green;
height:300px
}
transition-delay: time;
transition-timing-function: value;
顺序为:
transition: property duration timing-function delay | initial | inherit
.box{
width:100px;
height:100px;
background:blue;
transition:width,height 3s;
-moz-transition:width,height 3s; /* Firefox 4 */
-webkit-transition:width,height 3s; /* Safari and Chrome */
-o-transition:width,height 3s; /* Opera */
}
.box:hover{
width:400px;
height:300px;
}
使用时要再加上前缀,让属性在每个浏览器能够支援
-moz- /* firefox浏览器 */
-webkit- /* Safari, google浏览器 */
-o- /* Opera浏览器(早期) */
-ms- /* Internet Explorer */
animation-name是设定@keyframes动画名称
animation-name: keyframe动画名称
要与animation-duration属性搭配,不然动画不会执行
animation-duration: time;
animation-direction: normal|alternate;
animation-delay: time;
animation-duration 和 animation-delay前者是动画持续时间,後者为动画延迟时间
动画的速度曲线
animation-timing-function: value
animation-iteration-count: number |infinite
number:播放次数,预设是1,0的不会执行
inifinite:无限次数执行
animation-play-state: paused|running
顺序为:
animation: name duration timing-function delay iteration-count direction;
<div class="box"></div>
.box{
width:100px;
height:100px;
background:orange;
position:relative;
animation:mymove 5s infinite;
-webkit-animation:moveBox 5s infinite; /*Safari and Chrome*/
}
@keyframes movebox{
from {left:0px;}
to {left:200px;}
}
/*Safari and Chrome*/
@-webkit-keyframes movebox{
from {left:0px;}
to {left:200px;}
}
@keyframes animationname {
keyframes-selector {
css-styles;
}
}
搭配frome-to来做动画设定
.box{
position:relative;
animation:moveBox 5s infinite;
}
@keyframes moveBox{
from {top:0px;}
to {top:200px;}
}
搭配百分比来做动画设定
.box{
position:relative;
animation:moveBox 5s infinite;
}
@keyframes moveBox{
0% {background: red;}
50% {background: green;}
100% {background: blue;}
}
除了自己写动画,网路上也有CSS 的动画特效库
Animation.css
需要引入css档案,安装方式有两种
方法一:CDN方式
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
方法二:npm或yarn
npm
npm install animate.css --save
yarn
yarn add animate.css
下载完後再import
import "animate.css"
只要在标签元素添加class名称animate__animated以及任一动画名称如 animate__bounce(记得前缀 animate__!)就会有效果了
<h1 class="animate__animated animate__bounce">An animated element</h1>
里面提供数十种的淡入、淡出、旋转等效果,不需要额外引入JS,只要选好自己的样式後,点选右上角的 {‧} 按钮,检视原始码,把他复制到你的档案里面了
介绍了渐变与动画,你一定会问他们两者之间有什麽差别,transition是需要被触发才会执行,像是滑鼠移入(hover)效果,animation则是直接就执行。。
<<: Day26 跟着官方文件学习Laravel-Service Provider
身为机人控,《新世纪福音战士》真的是爱作XD虽然可能有人看不太懂,或是被结尾粪作气到。但作为机器人动...
更新: Bug解掉了,在第28天 今天真的没办法思考.. 还没抓到昨天的错误是为什麽,然後接下来的学...
费式数列 (引用至维基面科) 斐波那契数列(义大利语:Successione di Fibonacc...
前言 这个市场想要找工作的准工程师非常多,我们要证明自己除了学科(考题、技术问答)以外,更重要的是证...
今天来说说温湿度读取的部分吧,首先来看看这颗的Datasheet: https://www.sila...