transition: property duration timing-function delay;
transition-property: transition-duration: transition-timing-function: transition-delay:
| item | desc |
|---|---|
| property | 元素参与过渡的属性,必须是 数值型 的属性
通常指定为 all;建议 指定为特定属性 |
| duration | 过渡持续时间,单位秒 s 或毫秒 ms,必选参数,且必须是第一个时间参数;第二个时间参数是延迟时间
UI界面的过渡通常不超过 0.4s |
| timing-function | 时间函数,过渡的效果/方式
默认是 ease |
| delay | 过渡延迟时间,必须是第二个时间参数;第一个时间参数是过渡时间 |
| item | desc |
|---|---|
| linear | 以相同速度开始到结束( cubic-bezier(0, 0, 1, 1) ) |
| ease | 默认;开始慢,然后快,慢下来,结束时非常慢( cubic-bezier(0.25, 0.1, 0.25, 1)) |
| ease-in | 开始慢,结束快( cubic-bezier(0.42,0,1,1) |
| ease-out | 开始快,结束慢( cubic-bezier(0,0,0.58,1) |
| ease-in-out | 中间快,两边慢( cubic-bezier(0.42,0,0.58,1) |
| cubic-bezier(n,n,n,n) | 在 cubic-bezier 函数中定义自己的值;更多使用,请访问 Easing Wizard |
| steps() | 步进方式变换,见后续内容 |
.demo {
background-color: #ccc;
transition: 1s;
}
.demo:hover {
background-color: #f40;
}
.demo {
background-color: #ccc;
transition: background-color 1s;
}
.demo:hover {
background-color: #f40;
}
.demo {
background-color: #ccc;
transition: background-color 1s;
}
.demo:hover {
background-color: #f40;
transition: background-color 3s;
}
.demo {
background-color: #ccc;
font-size: 16px;
transition:
background-color 1s,
font-size 1s;
}
.demo:hover {
background-color: #f40;
font-size: 20px;
transition:
background-color 1s,
font-size 1s;
}
.demo {
background-color: #ccc;
font-size: 16px;
transition:
background-color 1s,
font-size 1s;
}
.demo:hover {
background-color: #f40;
font-size: 20px;
transition:
background-color 1s,
font-size 1s 1s;
}
.info-card img {
position: relative;
z-index: 1;
transform-origin: left top;
transition: .5s;
}
.info-card:hover img {
transform: scale(0.8);
transition: 1s;
}
.mars .img {
transform-origin: top;
transition: .4s;
}
.mars:hover .img {
transform: scale(.5);
}
.mars .info {
position: absolute;
left: 0px;
bottom: -60px;
//......
transition: .4s;
}
.mars:hover .info {
bottom: 0px;
}
.rot div {
position: absolute;
left: -230px;
top: -230px;
width: 80%;
height: 80%;
border: 10px solid #b22222;
transform-origin: left top;
transition: 1s;
}
.rot:hover div {
left: 10%;
top: 10%;
transform: rotate(360deg);
}
.tran div::after {
content: '';
position: absolute;
left: 0;
bottom: -180px;
width: 320px;
height: 180px;
background-color: #fff;
transform-origin: left top;
transition: 1s;
}
.tran div:hover::after {
transform: rotate(-20deg);
}
.border::before {
content: '';
position: absolute;
left: 50%;
top: 50%;
width: 60%;
height: 50%;
border: solid #b22222;
border-width: 4px 0;
transform: translate(-50%, -50%) scaleX(0);
transition: .4s;
}
.border::after {
content: '';
position: absolute;
left: 50%;
top: 50%;
width: 50%;
height: 60%;
border: solid #b22222;
border-width: 0px 4px;
transform: translate(-50%, -50%) scaleY(0);
transition: .4s;
}
.border:hover::before {
transform: translate(-50%, -50%) scaleX(1);
}
.border:hover::after {
transform: translate(-50%, -50%) scaleY(1);
}
steps(number_of_steps,direction)
.loading {
display: flex;
width: 300px;
height: 40px;
border: 1px solid #f40;
padding: 4px;
margin: 100px auto;
}
.loading::before {
content: '';
width: 0%;
height: 100%;
background-color: #f40;
transition: width 1s linear;
}
.loading:hover::before {
transition: width 5s steps(5);
width: 100%;
}
| item | desc |
|---|---|
| transitionstart | 动画开始 |
| transitionrun | 动画运行 |
| transitionend | 动画结束 |
| transitioncancel | 动画取消 |
el.addEventListener("transitionstart", (event) => {});
el.addEventListener("transitionrun", (event) => {});
el.addEventListener("transitionend", (event) => {});
el.addEventListener("transitioncancel", (event) => {});
const wrap = document.querySelector('.demo-wrap');
const btn = document.querySelector('.btn');
btn.addEventListener('click', () => {
wrap.classList.toggle('active');
})
wrap.addEventListener('transitionend', () => {
if (wrap.classList.contains('active')) {
}
window.location.href = './index.html';
})