1.transform: translateY(100px);
但是transform在單獨使用的時候並不會產生動畫效果,
頁面加載的時候就已經在變化后的狀態了,所以需要搭配transition使用,產生動畫效果。
這種需要hover 給他一個事件 才會發生這個動作
使用方法:
.a:hover{ transform: translateY(-50px); }
.a{ transition:all 1s ease-in-out 0.1s } 所有動畫 完成時間1s 變化曲線 延遲0.1s
.a{ transition:all 1s 1s forwards } 當動畫完成后,保持最后一個屬性值
注意 linear 可以讓旋轉沒間隙
2.完成過渡效果需要多少秒或毫秒 (2s)
3.規定速度效果的速度曲線 (linear勻速\ease慢快慢\eare-in慢快\eare-out快慢\ease-in-out慢快慢,和eare速度上有差異),這個屬性還可以使用cubic-bezier(n,n,n,n)自己定義,n的范圍在0-1之間。
4.定義過渡效果何時開始(2s)
2 用jquery控制 css方式做動畫
1. 點擊增加clss 關閉 刪除css
<script>
$("span").click(function () {
$("div").addClass("donghua")
})
$(".close").click(function () {
$("div").removeClass("donghua")
})
</script>
2. 可以用 scale 從0到1的方式變換,也可以改變width和height方式變化 注意 配合 transition
.less{width: 10px;height: 10px;
background-color: red;transform: scale(1);
transition: all 0.5s;
box-shadow: 100px 100px black 10px;
}
.donghua{
transform: scale(1);
width: 400px;height: 400px;
display: block;
opacity: 1;
transform-origin:100px 100px ;
}
3.定義動畫
@keyframes move-h1{
0% {transform: rotate(0deg); color: blue;}
50% {transform: rotate(360deg); color: orange;}
100% {transform: rotate(720deg); color: blue;}
}
.class{
animation: move-h1 10.5s ease-in-out forwards } 當動畫完成后,保持最后一個屬性值
animation: quan 3s infinite linear;

知識點:transform: rotate3d(0, 1,0, 90deg);可以隱藏元素
4.transform-origin旋轉基點

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
padding: 0;
margin: 0;
list-style: none; }
.na{
perspective:1000px;
background-color: red;
text-align: center;
width: 440px;height:30px;
border: 1px solid black;
margin-bottom: 20px;
}
.nav li{
border: 10px solid blue;
width: 440px;height: 30px;
margin-top:20px;
text-align: center;
background-color: orange;
}
body>ul{
margin-left: 100px;
}
.nav li{
transform: rotate3d(0, 1,0, 90deg);
transition: all .6s;
}
.na:hover .nav li{
transform: rotate3d(0, 1, 0, 0deg);
}
.nav li:nth-child(1) {
transition-delay: 0ms;
}
.nav li:nth-child(2) {
transition-delay: 100ms;
}
.nav li:nth-child(3) {
transition-delay: 200ms;
}
.nav li:nth-child(4) {
transition-delay: 300ms;
}
.nav li:nth-child(5) {
transition-delay: 400ms;
}
.nav li:nth-child(6) {
transition-delay: 500ms;
}
</style>
</head>
<body>
<ul>
<li class="na">展示
<ul class="nav">
<li>01</li>
<li>2</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</li>
</ul>
<p>看是否影響下面的位置<看是否影響下面的位置<看是否影響下面的位置<看是否影響下面的位置<看是否影響下面的位置<看是否影響下面的位置</p>
</body>
</html>
5.動畫補充
給背景做漸變 並且移動:
思路: background 設置 漸變 45deg,red20%, 40%
background-size:400%;
background-position:0% 100%
動畫做到 到 background-position:100% 0%
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<style>
body,html{width: 100%;height: 100%;margin: 0}
.wrap{width: 100%;
height: 100%;
background:linear-gradient(45deg,#394280 25%,#7820B1 50%,#E410DE 75%,#ED0639 100%);
background-size: 400%;
background-position: 0% 100%;
animation: move 10.5s infinite;
}
@keyframes move{
0%{background-position: 0% 100%;}
50%{background-position: 100% 0%;}
100%{background-position: 0% 100%;}
}
.wrap div{
width: 200px;height: 200px;border: 1px solid #000;display: inline-block;
position: fixed;
}
.ani .box:nth-child(1){
-webkit-animation-delay:3.5s!important;
}
.wrap div:nth-child(1){
left: 38.7%;top:51%;
}
.ani .box:nth-child(2),.wrap div:nth-child(2){
background: red;
left: 44.7%;top:52%;
animation-delay:3.5s!important;
}
.ani .box:nth-child(3),.wrap div:nth-child(3){
background: pink;
left: 57.7%;top:52.6%;
animation-delay:3s!important;
}
.wrap div::after{
content: "";
display: inline-block;
width: 20px;height: 20px;background-color: white;
border-radius: 50%;
}
.box{
transform: rotateZ(0deg);
animation: circle 2s linear 1;
}
@keyframes circle{
0%{transform: rotateZ(0deg);}
50%{transform: rotateZ(180deg);}
100%{transform: rotateZ(360deg);}
}
p{font-size: 60px;
position: absolute;
left: 50%;top: 50%;color: white;
transform: translate(-50%, -50%)}
.ani .box{
transform: rotateZ(0deg);
animation: circle 2s linear infinite;
}
</style>
</head>
<body>
<div class="wrap">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<p>loading</p>
</div>
<script>
setTimeout(function () {
$(".wrap").addClass("ani")
},3000)
</script>
</body>
</html>
