效果图
项目demo链接
实习思路
<button onclick="start()">again</button>
<p class="landIn">Ano hi watashitachi mada shiranai no Fushigi no monogatari desu.</p>
<style>
body {
display: flex;
flex-direction: column;
height: 100vh;
justify-content: center;
align-items: center;
background-image: linear-gradient(rgba(16, 16, 16, 0.8), rgba(16, 16, 16, 0.8)),
url(https://i.loli.net/2019/10/18/buDT4YS6zUMfHst.jpg);
background-size: cover;
}
p {
margin: 0 9em;
font-size: 2em;
font-weight: 600;
}
.landIn {
display: flex;
flex-wrap: wrap;
line-height: 1.8;
color: white;
font-family: Lora, serif;
white-space: pre;
}
.landIn span {
animation: landIn 0.8s ease-out both;
}
@keyframes landIn {
from {
opacity: 0;
transform: translateY(-20%);
}
to {
opacity: 1;
transform: translateY(0);
}
}
</style>
<script>
function start() {
const dom = document.getElementsByClassName('landIn')[0];
if (dom) {
let letters = dom.textContent.split('');
dom.textContent = '';
letters.forEach((letter, i) => {
let span = document.createElement('span');
span.textContent = letter;
span.style.animationDelay = `${i * 0.05}s`;
dom.append(span);
});
}
}
start();
</script>