移动Web 第二天
u 空间转换
1.使用transform属性实现元素在空间内的位移、旋转、缩放等效果
l transform: translate3d(x, y, z);
l transform: translateX(值);
l transform: translateY(值);
l transform: translateZ(值);
l 取值(正负均可)
l 像素单位数值 l 百分比
2. 使用perspective属性实现透视效果
属性(添加给父级)
Ø perspective: 值;
Ø 取值:像素单位数值, 数值一般在800 – 1200。
l 作用
Ø 空间转换时,为元素添加近大远小、近实远虚的视觉效果
3. 使用rotate实现元素空间旋转效果
Ø transform: rotateZ(值);
Ø transform: rotateX(值);
Ø transform: rotateY(值);
4. 使用transform-style: preserve-3d呈现立体图形
Ø 添加 transform-style: preserve-3d;
Ø 使子元素处于真正的3d空间
搭建立方体
调节a标签的位置
Ø a标签定位(子绝父相)
Ø 英文部分添加旋转和位移样式
Ø 中文部分添加位移样式
<!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>
</head>
<body>
<div class="box"></div>
<br />
<br />
<div class="box2"></div>
</body>
</html>
<style>
.box {
width: 200px;
height: 100px;
background-color: rgb(224, 114, 114);
animation: move 2s;
}
@keyframes move {
to {
width: 600px;
background-color: rgb(16, 104, 67);
}
}
.box2 {
width: 200px;
height: 100px;
background-color: tomato;
animation: run 2s;
}
@keyframes run {
50% {
width: 500px;
height: 300px;
background-color: pink;
}
100% {
width: 800px;
height: 500px;
background-color: rgb(56, 37, 37);
}
}
</style>
立体3d案例
<style>
* {
padding: 0;
margin: 0;
}
input {
width: 50px;
}
.box {
width: 200px;
height: 200px;
position: relative;
margin: 100px auto;
perspective-origin: 0px 0px;
transform-style: preserve-3d;
transform: rotate3d(1, 1, 1, 30deg);
}
.box>div {
width: 200px;
height: 200px;
position: absolute;
left: 0;
top: 0;
opacity: 0.9;
font-size: 30px;
}
::input-selection {
background-color: #000;
color: #fff;
}
.front {
background-color: #ff1703;
}
.back {
background-color: #ffc629;
}
.left {
background-color: #53ff27;
}
.right {
background-color: #18ffe4;
}
.top {
background-color: #0c00ff;
}
.bottom {
background-color: #ff21cb;
}
.front {
transform: translateZ(100px);
}
.back {
transform: translateZ(-100px) rotateY(180deg);
}
.left {
transform: translateX(-100px) rotateY(-90deg);
}
.right {
transform: translateX(100px) rotateY(90deg);
}
.top {
transform: translateY(-100px) rotateX(90deg);
}
.bottom {
transform: translateY(100px) rotateX(-90deg);
}
body {
perspective: 1000px;
}
</style>
</head>
<body>
<div class="box">
<div class="front">前面</div>
<div class="back">后面</div>
<div class="left">左边</div>
<div class="right">右边</div>
<div class="top">上面</div>
<div class="bottom">下面</div>
</div>
</body>
5. 使用scale实现空间缩放效果
Ø transform: scaleX(倍数);
Ø transform: scaleY(倍数);
Ø transform: scaleZ(倍数);
Ø transform: scale3d(x, y, z);
u 动画
1. 使用animation添加动画效果
<!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>
</head>
<body>
<div class="box"></div>
</body>
</html>
<style>
.box {
width: 200px;
height: 200px;
background-color: rgb(70, 50, 50);
animation: ani_1 2s infinite;
animation-name: ani_1;
animation-duration: 2s;
animation-delay: 3s;
animation-fill-mode: both;
animation-timing-function: steps;
animation-iteration-count: infinite;
animation-duration: alternate;
animation-play-state: paused;
}
@keyframes ani_1 {
0% {
background-color: rgb(51, 36, 36);
}
30% {
background-color: rgb(82, 26, 26);
border-radius: 50%;
}
100% {
background-color: rgb(82, 26, 61);
height: 100px;
width: 150px;
}
}
</style>
动画的本质是快速切换大量图片时在人脑中形成的具有连续性的画面
构成动画的最小单元:帧或动画帧
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1,minimum-scale=1,user-scalable=no" />
<title>01-动画实现步骤.html</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
div {
width: 200px;
height: 200px;
background-color: aqua;
animation-name: ani_1;
animation-duration: 2s;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-play-state: paused;
}
@keyframes ani_1 {
0% {
background-color: black;
width: 10px;
}
100% {
background-color: yellow;
border-radius: 50%;
width: 800px;
}
}
div:hover {
animation-play-state: paused;
animation-play-state: running;
}
</style>
</head>
<body>
<div>动画的体验</div>
</body>
</html>
逐帧动画:帧动画。开发中,一般配合精灵图实现动画效果。
animation-timing-function: steps(N);
Ø 将动画过程等分成N份
精灵动画制作步骤
Ø 准备显示区域
Ø 设置盒子尺寸是一张小图的尺寸,背景图为当前精灵图
Ø 定义动画
Ø 改变背景图的位置(移动的距离就是精灵图的宽度)
Ø 使用动画
Ø 添加速度曲线steps(N),N与精灵图上小图个数相同
Ø 添加无限重复效果