Một phương pháp khác là sử dụng API Web Animations của JS kết hợp với CSS
Ví dụ
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
body,
html {
height: 100vh;
}
header {
height: 20%;
}
.text-center {
text-align: center;
}
.leading-none {
line-height: 1;
}
.leading-3 {
line-height: .75rem;
}
.leading-2 {
line-height: .25rem;
}
.bg-black {
background-color: rgba[0, 0, 0, 1];
}
.bg-gray-50 {
background-color: rgba[249, 250, 251, 1];
}
.pt-12 {
padding-top: 3rem;
}
.pt-2 {
padding-top: 0.5rem;
}
.text-lightGray {
color: lightGray;
}
.container {
display: flex;
/* or inline-flex */
justify-content: space-between;
}
.container section {
padding: 0.5rem;
}
.opacity-0 {
opacity: 0;
}
Hello
Ipsum lipmsum emus tiris mism
ipsum 1
Cras purus ante, dictum non ultricies eu, dapibus non tellus. Nam et ipsum nec nunc vestibulum efficitur nec nec magna. Proin sodales ex et finibus congue
ipsum 2
Cras purus ante, dictum non ultricies eu, dapibus non tellus. Nam et ipsum nec nunc vestibulum efficitur nec nec magna. Proin sodales ex et finibus congue
ipsum 3
Cras purus ante, dictum non ultricies eu, dapibus non tellus. Nam et ipsum nec nunc vestibulum efficitur nec nec magna. Proin sodales ex et finibus congue
dictum non ultricies eu, dapibus non tellus
Ipsum lipmsum emus tiris mism
Phương pháp 1. Sử dụng thuộc tính hoạt hình CSS. Hoạt ảnh CSS được xác định bằng 2 khung hình chính. Một cái có độ mờ được đặt thành 0, cái còn lại có độ mờ được đặt thành 1. Khi loại hoạt ảnh được đặt thành dễ dàng, hoạt ảnh sẽ mờ dần trong trang. Thuộc tính này được áp dụng cho thẻ body. Bất cứ khi nào trang tải, hoạt ảnh này sẽ phát và trang sẽ xuất hiện mờ dần trong. Thời gian mờ dần có thể được đặt trong thuộc tính hoạt ảnh
cú pháp
body {
animation: fadeInAnimation ease 3s
animation-iteration-count: 1;
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
0async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
1async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
2async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
3
1
2____53
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
1
7
2____59
animation: fadeInAnimation ease 3s
0
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
1async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
1Ví dụ
animation: fadeInAnimation ease 3s
3
_______64____65____66
animation: fadeInAnimation ease 3s
7
animation: fadeInAnimation ease 3s
4animation: fadeInAnimation ease 3s
9animation: fadeInAnimation ease 3s
6
animation: fadeInAnimation ease 3s
4
3animation: fadeInAnimation ease 3s
6
2____56
2____58
____80____53____66
animation: fadeInAnimation ease 3s
7
animation: fadeInAnimation ease 3s
4animation-iteration-count: 1;
6animation: fadeInAnimation ease 3s
6
2____4
0
1
0animation-iteration-count: 1;
0
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
0
2____11
2____13
0
1
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
02
3
0
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
1
0
7
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
02
9
0
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
1
2____11
____80____86animation: fadeInAnimation ease 3s
6
animation-iteration-count: 1;
0animation: fadeInAnimation ease 3s
9animation: fadeInAnimation ease 3s
6
animation: fadeInAnimation ease 3s
7
animation: fadeInAnimation ease 3s
4
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
23____66
animation: fadeInAnimation ease 3s
4
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
27 animation-iteration-count: 1;
6async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
29async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
30animation: fadeInAnimation ease 3s
6
2____133
animation-iteration-count: 1;
0
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
27animation: fadeInAnimation ease 3s
6animation: fadeInAnimation ease 3s
0
animation: fadeInAnimation ease 3s
4
01animation: fadeInAnimation ease 3s
6
2____56
2____58
animation-iteration-count: 1;
0____501animation: fadeInAnimation ease 3s
6
animation: fadeInAnimation ease 3s
0
animation: fadeInAnimation ease 3s
4
14animation: fadeInAnimation ease 3s
6
2____517
2____519
animation-iteration-count: 1;
0
14animation: fadeInAnimation ease 3s
6
animation-iteration-count: 1;
0
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
23____66animation: fadeInAnimation ease 3s
7
animation-iteration-count: 1;
0animation: fadeInAnimation ease 3s
5animation: fadeInAnimation ease 3s
6
đầu ra
Phương pháp 2. Sử dụng thuộc tính chuyển đổi và đặt độ mờ thành 1 khi phần thân được tải. Trong phương pháp này, phần thân có thể được đặt thành độ mờ 0 ban đầu và thuộc tính chuyển đổi được sử dụng để tạo hiệu ứng động cho thuộc tính này bất cứ khi nào nó được thay đổi. Khi trang được tải, độ mờ được đặt thành 1 bằng cách sử dụng sự kiện tải. Do thuộc tính chuyển đổi, việc thay đổi độ mờ bây giờ sẽ xuất hiện mờ dần trong trang. Thời gian mờ dần có thể được đặt trong thuộc tính chuyển tiếp
cú pháp
body {
3
_______535
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
1Ví dụ
animation: fadeInAnimation ease 3s
3
_______64____65____66
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
2animation: fadeInAnimation ease 3s
4animation: fadeInAnimation ease 3s
9animation: fadeInAnimation ease 3s
6
animation: fadeInAnimation ease 3s
4
3animation: fadeInAnimation ease 3s
6
2____56
2____58
____80____53____66
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
2
animation: fadeInAnimation ease 3s
4animation-iteration-count: 1;
6animation: fadeInAnimation ease 3s
6
2____4
0
3
0
67
2____11
____80____86animation: fadeInAnimation ease 3s
6
animation-iteration-count: 1;
0animation: fadeInAnimation ease 3s
9animation: fadeInAnimation ease 3s
6
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
2animation: fadeInAnimation ease 3s
4
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
23
80async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
29
82animation: fadeInAnimation ease 3s
6animation: fadeInAnimation ease 3s
0
animation: fadeInAnimation ease 3s
4
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
27 animation-iteration-count: 1;
6async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
29async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
30animation: fadeInAnimation ease 3s
6
2____133
animation-iteration-count: 1;
0
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
27animation: fadeInAnimation ease 3s
6animation: fadeInAnimation ease 3s
0
animation: fadeInAnimation ease 3s
4
01animation: fadeInAnimation ease 3s
6
2____56
2____58
animation-iteration-count: 1;
0____501animation: fadeInAnimation ease 3s
6
animation: fadeInAnimation ease 3s
0
animation: fadeInAnimation ease 3s
4
14animation: fadeInAnimation ease 3s
6
2____517
2____519
animation-iteration-count: 1;
0
14animation: fadeInAnimation ease 3s
6
animation-iteration-count: 1;
0
async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
23____66async function moveToPosition[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
transform: `translateY[${el.getBoundingClientRect[].top}px]`
},
], {
duration: durationInMs,
easing: 'ease-in',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeIn[el, durationInMs] {
return new Promise[[resolve] => {
const animation = el.animate[[{
opacity: '0'
},
{
opacity: '0.5',
offset: 0.5
},
{
opacity: '1',
offset: 1
}
], {
duration: durationInMs,
easing: 'linear',
iterations: 1,
direction: 'normal',
fill: 'forwards',
delay: 0,
endDelay: 0
}];
animation.onfinish = [] => resolve[];
}];
}
async function fadeInSections[] {
for [const section of document.getElementsByTagName['section']] {
await fadeIn[section, 200];
}
}
window.addEventListener['load', async[] => {
await moveToPosition[document.getElementById['headerContent'], 500];
await fadeInSections[];
await fadeIn[document.getElementsByTagName['footer'][0], 200];
}];
2animation-iteration-count: 1;
0animation: fadeInAnimation ease 3s
5animation: fadeInAnimation ease 3s
30
đầu ra
CSS là nền tảng của các trang web, được sử dụng để phát triển trang web bằng cách tạo kiểu trang web và ứng dụng web. Bạn có thể học CSS từ đầu bằng cách làm theo Hướng dẫn CSS và Ví dụ về CSS này