ๆฆ่ฆ
ใซใฉใชใฑใงใใญใใใฎ่ฒใๅคใใใใฎๆใใ CSS ใงๅ็พใใพใใ
ใใญใใใใชใบใ ใซๅใใใฆๅคใใใฎใฏใใใพใใใๆฐใๅใใใใใใพใใ
็ป้ขใซ่กจ็คบใใๆญ่ฉใฎ่ฆ็ด
ๆญ่ฉใฏ่กใใจใๆๅญใใจใซใใญใใใฎใฟใคใใณใฐใๆฑบใพใฃใฆใใพใใใใใๆณๅฎใใฆใๆญ่ฉใไธๆๅญใใค span
ใฟใฐใงๆธใใพใใ
ใพใใใใญใใใฏใชใใใใซๅคใใใฎใงใๆๅญใใฉใใพใงๅกใใใฆใใใใ่กจใๅคๆฐใ style
ๅฑๆงใซ็จๆใใฆใใใพใใ
<div class="container">
<div class="lyrics">
<div class="lyrics--line">
<span class="syllable" style="--cursor: 0%">ใ</span>
<span class="syllable" style="--cursor: 0%">ใช</span>
<span class="syllable" style="--cursor: 0%">ใณ</span>
<span class="syllable" style="--cursor: 0%">ใฏ</span>
<span class="syllable" style="--cursor: 0%">ใ</span>
<span class="syllable" style="--cursor: 0%">ใผ</span>
<span class="syllable" style="--cursor: 0%">ใฏ</span>
<span class="syllable" style="--cursor: 0%">ๅคช</span>
<span class="syllable" style="--cursor: 0%">ใ</span>
<span>ใ</span>
<span class="syllable" style="--cursor: 0%">ๅคช</span>
<span class="syllable" style="--cursor: 0%">ใ</span>
<span class="syllable" style="--cursor: 0%">ใ</span>
<span>ใ</span>
<span class="syllable" style="--cursor: 0%">ba</span>
<span class="syllable" style="--cursor: 0%">by</span>
</div>
</div>
</div>
ๆญ่ฉใฎ่กจ็คบไฝ็ฝฎ
ๆญ่ฉใฏ้ๅธธใ็ป้ขไธใซ่กจ็คบใใใฎใงใalign-items: flex-end
ใจ justify-content: center
ใงๆญ่ฉใฎ่กไฝ็ฝฎใ่ชฟๆดใใพใใใพใใๆญ่ฉใฎๅๆๅญใฏ็ใไธญใซไธฆในใฆ้
็ฝฎใใใใฎใงใjustify-content: center
ใๆๅฎใใพใใ
html, body {
height: 98vh;
}
.container {
height: 100%;
background-image: url("./karaoke_saiten.png");
background-size: contain;
background-repeat: no-repeat;
background-position: center;
display: flex;
justify-content: center;
align-items: flex-end;
}
.lyrics {
font-size: 60px;
background-color: rgb(0 140 90 / 20%);
width: 100vw;
}
.lyrics--line {
display: flex;
justify-content: center;
-webkit-text-stroke: 1px darkblue;
}
ๆๅญใฎไธ้จๅใ ใ่ฒใๅคใใใใคใฎ่กจ็พ
ใใกใใๅ่ใซใใพใใใ
background
ใซ linear-gradient
ใๆๅฎใใใใจใงใ่ๆฏใใฐใฉใใผใทใงใณใใใใใจใใงใใพใใ
ๅทฆใใๅณๆนๅใฎๅ ดๅใฏ 90 ๅบฆๅ่ปขใใใใจ่ฏใใใใใงใใ
ๅฒๅใซใคใใฆใฏใๅทฆ็ซฏใใ ๆๅฎใใใใผใปใณใใผใธใพใง้ใใใไปฅ้ๅณ็ซฏใพใงใฏใฐใฌใผใซใใฆใใพใใ่ฒใใชใใใใซๅคๅใใ้จๅใฏ็กใใ่ฒใฎๅข็ใใฏใฃใใใใฆใใพใใ
background-clip
ใไฝฟใใจใ่ๆฏใ็นๅฎใฎ็ฏๅฒใซใ ใ่กจ็คบใใใใใจใใงใใพใใtext
ใๆๅฎใใใใจใงใๆๅญ้จๅใซใ ใ่ๆฏใๆๅฎใใใๆๅญ่ฒใ้ไธญใงๅใๆฟใใฃใฆใใใใใซ่ฆใใใใจใใงใใพใใ
่ๆฏใฎ่ฒใ่ฆใใใใใซใๆฌๆฅใฎๆๅญ่ฒใฏ้ๆ transparent
ใซใใฆใใใพใใ
.lyrics--line .syllable {
background: linear-gradient(90deg, blue 0 var(--cursor, 0), darkgrey var(--cursor, 0) 100%);
-webkit-background-clip: text;
color: transparent;
}
ๅๆๅญใฎ cursor ๅคๆฐใฎๅคใ 0% ใใ 100% ใฎ้ใงๅฅฝใใชใใใซๅคๆดใใใจใๆๅฎใใๅใ ใๆๅญใๅกใใใพใใ
ๆๅญ่ฒใๅพใ ใซๅคใใฆใใ
ไปๅใฏ็ป้ขใฎใฉใใใใฏใชใใฏใใใจๆๅญ่ฒใๅคใใฃใฆใใใใใซใใพใใ
ๅ้ณ็ฏใใจใซ 200 ms ใใใฆๆๅญใๅกใใคใถใใใใ--cursor
ใๅคๆดใใฆใใใพใใ
const playLyrics = () => {
const syllables = document.querySelectorAll('.syllable')
let offset = 0
for (const syllable of syllables) {
for (let i = 0; i < 100; i++) {
setTimeout(() => {
syllable.style.setProperty('--cursor', `${i + 1}%`)
}, offset)
offset += 2
}
}
}
document.querySelector('html').addEventListener('click', playLyrics, {once: true})
ๆๆณ
ใซใฉใชใฑใขใใช่ชไฝใฏใใใใๅบๅใฃใฆใใใใไฝ็ช็ ใใใใฃใฆๆใใงใใใใใใใฃใฆ่ชๅใงไฝใฃใฆใฟใใจๆฅฝใใใงใใญใใงใๆฒใฏๆขๅญใฎใใคใไฝฟใใจๆจฉๅฉใพใใใงใ้ใใใใใใใใใฎใงๅ จ้จ่ชไฝๆฒใซใใชใใจใใใพใใใใใใใจใฆใใคใใใงใใ
ใณใผใๅ จไฝ
ใณใผใๅ จไฝใ่ผใใฆใใใพใใฎใงใใๅ่ใพใงใซใ
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS ใงใซใฉใชใฑใฎใใญใใใๅ็พใใ</title>
<style>
html, body {
height: 98vh;
}
.container {
height: 100%;
background-image: url("./karaoke_saiten.png");
background-size: contain;
background-repeat: no-repeat;
background-position: center;
display: flex;
justify-content: center;
align-items: flex-end;
}
.lyrics {
font-size: 60px;
background-color: rgb(0 140 90 / 20%);
width: 100vw;
}
.lyrics--line {
display: flex;
justify-content: center;
-webkit-text-stroke: 1px darkblue;
}
.lyrics--line .syllable {
background: linear-gradient(90deg, blue 0 var(--cursor, 0), darkgrey var(--cursor, 0) 100%);
-webkit-background-clip: text;
color: transparent;
}
</style>
</head>
<body>
<div class="container">
<div class="lyrics">
<div class="lyrics--line">
<span class="syllable" style="--cursor: 0%">ใ</span>
<span class="syllable" style="--cursor: 0%">ใช</span>
<span class="syllable" style="--cursor: 0%">ใณ</span>
<span class="syllable" style="--cursor: 0%">ใฏ</span>
<span class="syllable" style="--cursor: 0%">ใ</span>
<span class="syllable" style="--cursor: 0%">ใผ</span>
<span class="syllable" style="--cursor: 0%">ใฏ</span>
<span class="syllable" style="--cursor: 0%">ๅคช</span>
<span class="syllable" style="--cursor: 0%">ใ</span>
<span>ใ</span>
<span class="syllable" style="--cursor: 0%">ๅคช</span>
<span class="syllable" style="--cursor: 0%">ใ</span>
<span class="syllable" style="--cursor: 0%">ใ</span>
<span>ใ</span>
<span class="syllable" style="--cursor: 0%">ba</span>
<span class="syllable" style="--cursor: 0%">by</span>
</div>
</div>
</div>
</body>
<script>
const playLyrics = () => {
const syllables = document.querySelectorAll('.syllable')
let offset = 0
for (const syllable of syllables) {
for (let i = 0; i < 100; i++) {
setTimeout(() => {
syllable.style.setProperty('--cursor', `${i + 1}%`)
}, offset)
offset += 2
}
}
}
document.querySelector('html').addEventListener('click', playLyrics, {once: true})
</script>
</html>
Comments
ใใฎ่พบใใฏใกใณใใใณใน็ญใ่ๆ ฎใใใจใ1ๆๅญใใคใซๅใใฆๅใใฟใฐใงๆฌใใใใใฒใจ็นใใใฎๆๅญๅใจใใฆ่จ่ฟฐใใฆใใใฆในใฏใชใใใงๅๅฒๅใณใฟใฐ่ฟฝๅ ๅฆ็ใใใๆนใๆฅฝใใจๆใใพใใ
Let's comment your feelings that are more than good