iT邦幫忙

2025 iThome 鐵人賽

DAY 19
0

目標

1.在 lyrics.js 中,填寫專輯每首歌的歌詞資料
2.確保從專輯列表點擊 Lyrics 按鈕可以顯示對應歌詞
3.從單曲展示區點及歌曲後顯示正確的歌詞


lyrics.js

(歌詞部分內容較多,所以程式碼有省略)

// 取得 URL 參數
const urlParams = new URLSearchParams(window.location.search);
const songId = urlParams.get('song');   

// 歌詞資料
const lyricsData = {
    "Requiem-Amen": `
        Sign of the times
        I don't pray to God, that's a weakness
        I been playing God in arenas
        I was doing better 'til I wanted more
        ...`,
    "Requiem-Say": `
        Say, say it
        You do this all the time
        ...`,
    "song1": `
        WANTCHU 歌詞
        ...`,
    "song2": `
        beside you 歌詞
        ...`
    // 可依序新增其他歌曲
};

// 歌名資料
const songTitles = {
    "song1": "WANTCHU",
    "song2": "beside you",
    "Requiem-Amen": "Amen",
    "Requiem-Say": "Say"
};

程式說明

  • 依照專輯與單曲建立 lyricsData 與 songTitles 物件
  • key 使用 URL 傳遞的 song 參數,例如 "Requiem-Amen"
  • 這樣能確保從專輯列表或單曲列表跳轉到歌詞頁面時,顯示對應的歌詞

畫面展示

https://ithelp.ithome.com.tw/upload/images/20251006/20168364HPwsxWCStE.png


上一篇
Lyrics 按鈕跳轉 + 專輯第一張歌詞
系列文
打造專屬於歌手的音樂資訊網頁:從零開始的前端實作與技術分享21
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言