LoginSignup

Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

0
0

ๆฆ‚่ฆ

ใ‚ซใƒฉใ‚ชใ‚ฑใงใƒ†ใƒญใƒƒใƒ—ใฎ่‰ฒใŒๅค‰ใ‚ใ‚‹ใ‚ใฎๆ„Ÿใ˜ใ‚’ CSS ใงๅ†็พใ—ใพใ™ใ€‚

karaoke.gif

ใƒ†ใƒญใƒƒใƒ—ใ‚’ใƒชใ‚บใƒ ใซๅˆใ‚ใ›ใฆๅค‰ใˆใ‚‹ใฎใฏใ‚„ใ‚Šใพใ›ใ‚“ใ€‚ๆฐ—ใŒๅ‘ใ„ใŸใ‚‰ใ‚„ใ‚Šใพใ™ใ€‚

็”ป้ขใซ่กจ็คบใ™ใ‚‹ๆญŒ่ฉžใฎ่ฆ็ด 

ๆญŒ่ฉžใฏ่กŒใ”ใจใ€ๆ–‡ๅญ—ใ”ใจใซใƒ†ใƒญใƒƒใƒ—ใฎใ‚ฟใ‚คใƒŸใƒณใ‚ฐใŒๆฑบใพใฃใฆใ„ใพใ™ใ€‚ใ“ใ‚Œใ‚’ๆƒณๅฎšใ—ใฆใ€ๆญŒ่ฉžใ‚’ไธ€ๆ–‡ๅญ—ใšใค 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>
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
noritakaIzumi

@noritakaIzumi(Noritaka IZUMI)

Web ็ณปใ‚จใƒณใ‚ธใƒ‹ใ‚ขใ€‚่‡ชๅ‹•โ—‹โ—‹ใซ่ˆˆๅ‘ณใ‚ใ‚Šใ€‚

JavaScript's like ranking last week

ใŠ้กŒใฏไธๅ•๏ผQiita Engineer Festa 2024ใง่จ˜ไบ‹ๆŠ•็จฟ๏ผ
degudegu2510

ใ€HTMLใ€‘ใƒœใ‚ฟใƒณ่ฆ็ด ใซdisabledๅฑžๆ€งใ‚’ใคใ‘ใ‚‹ใฎใ‚’ใ‚„ใ‚ใพใ›ใ‚“ใ‹๏ผŸ

ใŠ้กŒใฏไธๅ•๏ผQiita Engineer Festa 2024ใง่จ˜ไบ‹ๆŠ•็จฟ๏ผ
saba_uni_toro_

ใ€ๅ€‹ไบบ้–‹็™บใ€‘่‰ฒๅฝฉๆคœๅฎš1็ดšๅˆๆ ผใฎใƒ‡ใ‚ถใ‚คใƒŠใƒผใŒๆœฌๆฐ—ใงใ€Œ่‰ฒๅฝฉๆคœๅฎšใฎ่‰ฒๅใ‚ขใƒ—ใƒชใ€ใ‚’ไฝœใฃใŸ่ฉฑ

Comments

eufss0183
@eufss0183
<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>

       :

ใ“ใฎ่พบใ‚Šใฏใƒกใƒณใƒ†ใƒŠใƒณใ‚น็ญ‰ใ‚’่€ƒๆ…ฎใ™ใ‚‹ใจใ€1ๆ–‡ๅญ—ใšใคใซๅˆ†ใ‘ใฆๅŒใ˜ใ‚ฟใ‚ฐใงๆ‹ฌใ‚‹ใ‚ˆใ‚Šใ€ใฒใจ็น‹ใŒใ‚Šใฎๆ–‡ๅญ—ๅˆ—ใจใ—ใฆ่จ˜่ฟฐใ—ใฆใŠใ„ใฆใ‚นใ‚ฏใƒชใƒ—ใƒˆใงๅˆ†ๅ‰ฒๅŠใณใ‚ฟใ‚ฐ่ฟฝๅŠ ๅ‡ฆ็†ใ‚’ใ™ใ‚‹ๆ–นใŒๆฅฝใ‹ใจๆ€ใ„ใพใ™ใ€‚

<!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">
      ใƒ‰ใƒชใƒณใ‚ฏใƒใƒผใฏๅคชใ‚‹ใ€€ๅคชใ‚‹ใ‚ˆใ€€baby
    </div>
  </div>
</div>
</body>
<script>
  const lineElem = document.querySelector('.lyrics--line');
  lineElem.innerHTML = [...lineElem.textContent.trim()].
    map(v => `<span class="syllable" style="--cursor: 0%">${v}</span>`).join('');

  const speed = 2.5;
  const playLyrics = () => {
    document.querySelectorAll('.syllable').forEach((v, i) => {
      for (let t = 1; t <= 100; t++) {
        setTimeout(() => {
          v.style.setProperty('--cursor', `${t}%`);
        }, (i * 100 + t) * speed);
      }
    });
  };

  document.addEventListener('click', playLyrics, {once: true});
</script>
</html>
0

Let's comment your feelings that are more than good

Being held Article posting campaign

ใ‚ขใƒ—ใƒชใ‚ฑใƒผใ‚ทใƒงใƒณ้–‹็™บใซๆณจๅŠ›ใ™ใ‚‹ใŸใ‚ใฎๅทฅๅคซใ‚’ใ‚ทใ‚งใ‚ขใ—ใ‚ˆใ†๏ผ sponsored by Qmonus Value Stream

~
View details

็”ŸๆˆAIใซ้–ขใ™ใ‚‹่จ˜ไบ‹ใ‚’ๆ›ธใ“ใ†๏ผ

~
View details
0
0

Login to continue?

Login or Sign up with social account

Login or Sign up with your email address