一、渐变
1、线性渐变
语法:background-image:linear-gradient
方向:上、下、左、右、角度
默认的是top、to bottom、180deg
如果要添加方向,则必须使用浏览器的内核识别标识
-webkit- : safari & chrome
-moz- : firefox
-ms- : IE
-o- : opera
2、径向渐变
语法:background-image:radial-gradient
形状:circle / ellipse
终点:closest-side / closest-corner / farthest-side / farthest-corner
二、过渡
transition 在不适用动画的情况下变换状态
transition:all 1s 0.1s linear 顺序:属性名 时间 延迟时间 速度曲线
transition-property 设置过渡的属性
transition-duration 定义过渡时间
transition-delay 定义延时执行时间
transition-timing-function 过渡效果的时间曲线
(linear 匀速 ease 慢、快、慢 ease-in 慢、快 ease-out 快、慢 ease-in-out 慢、快、慢)
三、倒影
box-reflect
语法:box-reflect:方向 偏移量 蒙版或渐变
值:none 默认值 below above left right
四、变形
transform
平移 translate 旋转 rotate 伸缩 scale 拉伸 skew
3d效果 transform-style:preserved-3d
五、动画
关键帧 keyframes
动画
animation-name 动画属性名
animation-duration 动画持续时间
animation-delay 动画延续时间
animation-timing-function 动画速度曲线
animation-iteration-count 定义循环次数 ( infinite无限循环)
animation-play-state 动画状态 (值:paused running)
animation-fill-mode forwards保留最后一帧动画
六、第三方动画库
eg animation.css
使用第三方动画库可以帮助我们快速实现一些复杂动画
案例1
<!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>gradient</title>
<style>
body{
background-color: #666;
}
p{
width: 400px;
height: 100px;
font-size: 60px;
line-height: 100px;
text-align: center;
background-color: gold;
color: transparent;
background-image: -webkit-linear-gradient(135deg, transparent 15%, #fff 17%, transparent 19%);
/* 过渡 */
transition: 3s;
/* 背景剪裁 */
-webkit-background-clip: text;
}
p:hover{
background-position: 400px 0;
}
.yy{
width: 384px;
height: 216px;
background-image: url(../img/rjl.jpg);
background-size: cover;
mask-image: linear-gradient(left, #fff 20%, transparent 20%, transparent 40%, #fff 40%, #fff 60%, transparent 60%, transparent 80%, #fff 80%);
-webkit-mask-image: -webkit-linear-gradient(left, #fff 20%, transparent 20%, transparent 40%, #fff 40%, #fff 60%, transparent 60%, transparent 80%, #fff 80%);
transition: 3s;
}
.yy:hover{
background-position: 384px 0;
}
.bg{
width: 384px;
height: 216px;
background-image: -webkit-linear-gradient(left, #fff 20%, transparent 20%, transparent 40%, #fff 40%, #fff 60%, transparent 60%, transparent 80%, #fff 80%);
background-image: linear-gradient(left, #fff 20%, transparent 20%, transparent 40%, #fff 40%, #fff 60%, transparent 60%, transparent 80%, #fff 80%);
}
.ch{
width: 500px;
height: 300px;
background-image: -webkit-radial-gradient(center bottom, transparent 30%, purple,deepskyblue,cyan,greenyellow,gold,orange,tomato,transparent 50%);
}
</style>
</head>
<body>
<p>千山鸟飞绝</p>
<div class="yy"></div>
<div class="bg"></div>
<div class="ch"></div>
</body>
</html>
案例2
<!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>case02</title>
<style>
/* 定义帧动画 */
@keyframes bean_roll1 {
from {transform: rotate(0);}
to {transform: rotate(45deg);}
}
@keyframes bean_roll2 {
from {transform: rotate(0);}
to {transform: rotate(-45deg);}
}
/* @keyframes bean_roll1 {
0% {transform: rotate(0);}
50% {transform: rotate(45deg);}
100% {transform: rotate(0);}
}
@keyframes bean_roll2 {
0% {transform: rotate(0);}
50% {transform: rotate(-45deg);}
100% {transform: rotate(0);}
} */
@keyframes dou_move{
from{left: 200px;}
to{left: 80px;}
}
.bean{
width: 200px;
height: 200px;
background-color: #333;
position: relative;
}
.bean .cdr{
width: 0;
height: 0;
border: 50px solid gold;
border-right-color: transparent;
border-radius: 50%;
position: absolute;
left: 30px;
top: 50px;
}
.cdr:nth-of-type(1){
/* animation: 动画名称 动画执行时间 [延迟时间 动画曲线 执行次数 是否反向]*/
animation: bean_roll1 2s linear infinite alternate;
}
.cdr:nth-of-type(2){
/* animation: 动画名称 动画执行时间 [延迟时间 动画曲线 执行次数 是否反向]*/
animation: bean_roll2 2s linear infinite alternate;
}
.eye{
width: 16px;
height: 16px;
background-color: #333;
position: absolute;
left: 80px;
top: 66px;
border-radius: 50%;
}
.dou{
width: 16px;
height: 16px;
background-color: gold;
position: absolute;
left: 200px;
top: 92px;
border-radius: 50%;
animation: dou_move 2s infinite;
}
</style>
</head>
<body>
<div class="bean">
<div class="cdr"></div>
<div class="cdr"></div>
<div class="eye"></div>
<div class="dou"></div>
</div>
</body>
</html>
案例3
<!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>case03</title>
<style>
@keyframes roll {
from{
transform: rotateX(0) rotateY(0) rotateZ(0);
}
to{
transform: rotateX(360deg) rotateY(720deg) rotateZ(360deg);
}
}
*{
margin: 0;
padding: 0;
}
div{
width: 200px;
height: 200px;
position: absolute;
}
.wrap{
margin: 100px;
animation: roll 4s linear infinite;
/* 开启3d */
transform-style: preserve-3d;
}
.wrap div{
line-height: 200px;
text-align:center;
font-size: 100px;
color: #fff;
}
/* 左右 */
.wrap div:nth-of-type(1){
transform: rotateY(-90deg) translateZ(100px);
background-color: hotpink;
}
.wrap div:nth-of-type(2){
transform: rotateY(90deg) translateZ(100px);
background-color: deepskyblue;
}
/* 上下 */
.wrap div:nth-of-type(3){
transform: rotateX(90deg) translateZ(100px);
background-color: gold;
}
.wrap div:nth-of-type(4){
transform: rotateX(-90deg) translateZ(100px);
background-color: greenyellow;
}
/* 前后 */
.wrap div:nth-of-type(5){
transform: translateZ(100px);
background-color: pink;
}
.wrap div:nth-of-type(6){
transform: rotateX(180deg) translateZ(100px);
background-color: tomato;
}
</style>
</head>
<body>
<div class="wrap">
<div>A</div>
<div>B</div>
<div>C</div>
<div>D</div>
<div>E</div>
<div>F</div>
</div>
</body>
</html>
案例4
<!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>case09</title>
<style>
@keyframes roll {
from {transform: rotate(0);}
to {transform: rotate(360deg);}
}
.bg{
width: 200px;
height: 200px;
background-color: gold;
}
.clock{
box-sizing: border-box;
width: 100px;
height: 100px;
border: 4px solid #fff;
position: absolute;
left: 50px;
top: 50px;
border-radius: 50%;
}
.z1, .z2{
position: absolute;
width: 8px;
height: 50px;
background-color: #fff;
left: 96px;
top: 50px;
transform-origin: center bottom;
}
.z2{
height: 30px;
top: 70px;
animation: roll 12s linear infinite;
}
.z1{
animation: roll 2s linear infinite;
}
</style>
</head>
<body>
<div class="bg">
<div class="clock"></div>
<div class="z1"></div>
<div class="z2"></div>
</div>
</body>
</html>
案例5
<!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>轮播图</title>
<style>
/* @keyframes move {
0% {left: 0;}
25% {left: -400px;}
50% {left: -800px;}
75% {left: -1200px;}
100%{left: -1600px;}
} */
@keyframes move {
0% {left: 0;}
24% {left: 0;}
26%{left: -400px;}
49%{left: -400px;}
51% {left: -800px;}
74% {left: -800px;}
76% {left: -1200px;}
98% {left: -1200px;}
100%{left: -1600px;}
}
@keyframes dot{
0% {opacity: 1;}
24% {opacity: 1;}
25% {opacity: .7;}
100% {opacity: .7;}
}
*{
margin: 0;
padding: 0;
}
.wrap{
width: 400px;
height: 300px;
overflow: hidden;
position: relative;
margin: 0 auto;
}
.wrap .move{
width: 2000px;
height: 300px;
position: absolute;
animation: move 8s linear infinite;
}
.wrap .move img{
width: 400px;
height: 300px;
float: left;
}
.wrap .dots{
position: absolute;
width: 160px;
height: 16px;
border-radius: 8px;
background-color: rgba(0, 0, 0, .75);
bottom: 16px;
left: 120px;
display: flex;
justify-content: space-around;
align-items: center;
}
.wrap .dots .dot{
width: 10px;
height: 10px;
border-radius: 50%;
background-color: #fff;
opacity: .7;
animation: dot 8s linear infinite;
}
</style>
</head>
<body>
<div class="wrap">
<div class="move">
<img src="../img/1.jpg" alt="">
<img src="../img/2.jpg" alt="">
<img src="../img/3.jpg" alt="">
<img src="../img/4.jpg" alt="">
<img src="../img/1.jpg" alt="">
</div>
<div class="dots">
<div class="dot"></div>
<div style="animation-delay: 2s;" class="dot"></div>
<div style="animation-delay: 4s;" class="dot"></div>
<div style="animation-delay: 6s;" class="dot"></div>
</div>
</div>
</body>
</html>
案例6
<!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>work02</title>
<style>
@keyframes roll {
0% {transform: translateX(0);}
25% {transform: translateX(128px);}
50% {transform: translateX(128px) translateY(128px);}
75% {transform: translateX(0) translateY(128px);}
100% {transform: translateX(0) translateY(0);}
}
@keyframes cub{
0%{top: 100px;; opacity: 0;}
50%{top:50px; opacity: .5;}
100%{top: 0; opacity: 1;}
}
.bg{
width: 400px;
height: 400px;
background-color: #666;
position: relative;
}
.cube{
width: 100px;
height: 100px;
background-color: transparent;
border: 2px solid #fff;
position: absolute;
top: 148px;
left: 148px;
overflow: hidden;
}
.cub{
width: 100px;
height: 100px;
background-color: #fff;
position: absolute;
top: 104px;
opacity: 0;
animation: cub 4s linear infinite;
}
.big{
box-sizing: border-box;
width: 124px;
height: 124px;
border: 2px solid transparent;
background-color: transparent;
position: absolute;
top: 132px;
left: 132px;
transform-style: preserve-3d;
animation: roll 2s linear infinite;
}
.roll{
width: 8px;
height: 8px;
background-color: #fff;
position: absolute;
}
</style>
</head>
<body>
<div class="bg">
<div class="cube">
<div class="cub"></div>
</div>
<div class="big">
<div class="roll"></div>
</div>
</div>
</body>
</html>