|
|

楼主 |
发表于 2024-1-5 12:31
|
显示全部楼层
本帖最后由 马黑黑 于 2024-1-5 15:03 编辑
代码:- <style>
- #mydiv { margin: -70px 0 0 calc(50% - 593px); width: 1024px; height: 678px; border: 4px solid rgba(0,0,0,.15); border-radius: 10px; background: gray url('https://638183.freep.cn/638183/t23/2/gvrf.jpg') no-repeat center/cover; box-shadow: 4px 4px 16px rgba(0,0,0,.25); position: relative; display: grid; place-items: center; }
- #mydiv::before { position: absolute; content: attr(data-title); left: 20px;top: 10px; font: bold 2em/2.2em sans-serif; color: snow; text-shadow: 1px 1px #000; }
- #rili { padding: 6px; top: 10px; max-width: 222px; display: flex; flex-direction: row; flex-wrap: wrap; color: #eee; box-sizing: border-box; position: absolute; }
- #rili::before { position: absolute; content: attr(data-bg); width: 100%; height: 100%; color: rgba(0,0,0,.25); display: grid; place-items: center; font: bold 2em sans-serif; }
- #iRed { position: absolute; color: red; transition: .5s; }
- #iRed:hover { font-size: 40px; font-weight: bold; }
- #myplayer { position: absolute; cursor: pointer; animation: rotating 5s infinite linear var(--state); }
- .tbox { width: 30px; height: 26px; text-align: center; font: normal 16px/26px sans-serif; cursor: pointer; z-index: 10; }
- .tbox:hover { color: pink; }
- .tbox:active { color: navy; }
- @keyframes rotating { to { transform: rotate(360deg); } }
- </style>
- <div id="mydiv">
- <audio id="aud" src="https://music.163.com/song/media/outer/url?id=22651392" autoplay loop></audio>
- <div id="rili"></div>
- <img id="myplayer" src="https://638183.freep.cn/638183/t23/btn/hshx.png" alt="" />
- </div>
- <script>
- /* 音乐数组:总数不低于31个,来源于网易云音乐,或URL同一个网站前缀 + 不同后缀(需修改 playSong 函数)*/
- let songs = [ ["完美主义","1983524772"], ["Enzalla - Spira","429261487"], ["小河小河","2062919073"], ["Dont Say No","22651392"], ["大西厢","136724"], ["筝鸣","1300995139"], ["红古尔","2029165786"], ["老唱片的诱惑","1415245956"], ["风云榜","201876"], ["酹江月","1357056838"], ["暗夜舞者","1950170789"], ["Strobe","22417149"], ["殊途同归","1848494864"], ["战曲","552433256"], ["落山风","2005329783"], ["梦驼铃","359379"], ["月是故乡明","1965108307"], ["滚滚长江东逝水","27591735"], ["失序者","2087973934"], ["网","526547640"], ["月光の雲海","442760"], ["云","520459540"], ["似水年华","2085110548"], ["冰の星","1343982589"], ["鸿蒙","2068482355"], ["檐下客","1298410511"], ["半纸心事","1914628093"], ["逃脱引力","1996509752"], ["精神入侵","1810150717"], ["关山月","1451656076"], ["问情","1481922620"] ];
- /* 画日历并播放今天曲目 */
- (function () {
- let ar = '日一二三四五六'.split('').map(c => `<div class="tbox">${c}</div>`);
- let output = ar.join('');
- let y = new Date().getFullYear(), m = new Date().getMonth();
- let days = new Date(y, m+1, 0).getDate();
- let day1st = new Date(y, m).getDay();
- let today = new Date().getDate();
- Array.from({length: days + day1st}).forEach((item,key) => {
- let idx = key < day1st ? '' : (key - day1st + 1);
- if(idx) {
- if(idx == today) idx = `<span id="iRed">${idx}</span>`;
- let sUrl = songs[key - day1st][1], sName = songs[key - day1st][0];
- output += `<div class="tbox" title="${sName}" onclick="playSong(${sUrl},'${sName}');this.style.color='navy';">${idx}</div>`;
- }else{
- output += '<div class="tbox"></div>';
- }
- });
- rili.innerHTML = output;
- rili.dataset.bg = `${y}年${m+1}月`;
- let songName = songs[today - 1][0], songUrl = songs[today - 1][1];
- playSong(songUrl,songName);
- })();
- /* 播放音频函数 :相同的url前缀 + 不同的后缀id */
- function playSong(id,song) {
- let url = 'https://music.163.com/song/media/outer/url?id=' + id;
- aud.src = url;
- mydiv.dataset.title = song;
- };
- /* 其他相关操作 */
- let mState = () => mydiv.style.setProperty('--state', aud.paused ? 'paused' : 'running');
- aud.addEventListener('playing', mState, false);
- aud.addEventListener('pause', mState, false);
- myplayer.addEventListener('click', () => aud.paused ? aud.play() : aud.pause());
- </script>
复制代码
|
评分
-
| 参与人数 2 | 威望 +100 |
金钱 +200 |
经验 +100 |
收起
理由
|
小辣椒
| + 50 |
+ 100 |
+ 50 |
赞一个! |
红影
| + 50 |
+ 100 |
+ 50 |
赞一个! |
查看全部评分
|