加林森 发表于 2022-6-6 22:25

本帖最后由 加林森 于 2022-8-27 21:28 编辑 <br /><br />马黑黑 发表于 2022-6-6 22:16
喝另外的
嗯嗯,我的酒有很多种的。都是川酒。

<style>
#papa { left: -214px; width: 1024px; height: 640px; display: grid;url('https://pic.imgdb.cn/item/630a0f1a16f2c2beb1b01652.jpg') no-repeat;place-items: center; background: snow; box-shadow: 3px 3px 20px #000; position: relative; }
#player { padding: 10px; position: absolute;bottom: 20px; width: fit-content; height: fit-content; display: flex; gap: 10px; flex-direction: column;1px solid; }
#lrctext { font: normal 1.2em sans-serif; color: olive; text-shadow: 1px 1px 2px #000; text-align: center; }
#btnwrap { width: fit-content; height: fit-content; display: flex; gap: 8px; align-items: center; }
#btnplay { outline: none; cursor: pointer; }
#btnplay:hover { color: red; }
#prgline { width: 200px; height: 2px; background: no-repeat ; background-size: 1px 2px; display: block; cursor: pointer;}
#tmsg { width: auto;}
</style>

<div id="papa">
      <div id="player">
                <div id="lrctext">lrc歌词</div>
                <div id="btnwrap">
                        <input type="button"id="btnplay" value="播放" />
                        <span id="prgline"></span>
                        <span id="tmsg">00:00 | 00:00</span>
                </div>
      </div>
</div>

<script>
let lrcAr = [
      ['0.01','童安格耶利亚女郎'],
      ['34.10','很远的地方有个女郎名字叫做耶利亚'],
      ['42.33','有人在传说她的眼睛看了使人更年轻'],
      ['50.62','如果你得到她的拥抱你就永远不会老'],
      ['59.15','为了这个神奇的传说我要努力去寻找'],
      ['66.42','耶利亚神秘耶利亚耶利耶利亚'],
      ['74.77','耶利亚神秘耶利亚我一定要找到她'],
      ['101.12','很远的地方有个女郎名字叫做耶利亚'],
      ['109.32','有人在传说她的眼睛看了使人更年轻'],
      ['117.90','如果你得到她的拥抱你就永远不会老'],
      ['126.22','为了这个神奇的传说我要努力去寻找'],
      ['133.57','耶利亚神秘耶利亚耶利耶利亚'],
      ['141.90','耶利亚神秘耶利亚我一定要找到她'],
      ['150.29','耶利亚神秘耶利亚耶利耶利亚'],
      ['158.76','耶利亚神秘耶利亚我一定要找到她'],
      ['198.70','耶利亚神秘耶利亚耶利耶利亚'],
      ['207.11','耶利亚神秘耶利亚我一定要找到她'],
      ['215.28','耶利亚神秘耶利亚耶利耶利亚'],
      ['223.72','耶利亚神秘耶利亚我一定要找到她']
];
let aud = new Audio(), lw = prgline.offsetWidth;
aud.src = 'https://music.163.com/song/media/outer/url?id=1876788950.mp3';
aud.autoplay = true;
aud.loop = true;

prgline.onclick = (e) => aud.currentTime = aud.duration * e.offsetX / prgline.offsetWidth;

btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
aud.addEventListener('playing', ()=> btnplay.value = '暂停');
aud.addEventListener('pause', ()=> btnplay.value = '播放');

aud.addEventListener('timeupdate', () => {
      prgline.style.backgroundSize = lw * aud.currentTime / aud.duration + 'px 2px';
      tmsg.innerText = toMin(aud.duration) + ' | ' + toMin(aud.currentTime);
      for(j = 0; j < lrcAr.length;j ++) {
                if(aud.currentTime >= lrcAr) lrctext.innerText = lrcAr;
      }
});

let toMin = (val)=> {
      if (!val) return '00:00';
      val = Math.floor(val);
      let min = parseInt(val / 60), sec = parseFloat(val % 60);
      if(min < 10) min = '0' + min;
      if(sec < 10) sec = '0' + sec;
      return min + ':' + sec;
}
</script>

马黑黑 发表于 2022-6-6 22:26

加林森 发表于 2022-6-6 22:25
嗯嗯,我的酒有很多种的。都是川酒。

挺好挺好

加林森 发表于 2022-6-6 23:12

本帖最后由 加林森 于 2022-8-27 14:17 编辑 <br /><br />马黑黑 发表于 2022-6-6 22:26
挺好挺好
晚安,明天见!{:5_110:}

<style>
      #papa { left: -214px; width: 1024px; height: 640px; box-shadow: 3px 3px 20px #000; background: gray url('https://pic.imgdb.cn/item/6309b64f16f2c2beb1754d30.jpg') no-repeat center/cover; position: relative; z-index: 1; }
      #mypic { position: absolute; top: 125px; right: 100px; width: 260px; transform: rotate(30deg); cursor: pointer; transition: all 2s; }
      #mypic:hover { box-shadow: -10px -10px 40px 10px rgba(255,255,255,.45); transform: scale(1.5); }
      #player { margin: auto; display: block; position: absolute; }
</style>

<div id="papa">
      <canvas id="player"></canvas>
      <div id="wrapper"><img id="ball" src="https://pic.imgdb.cn/item/6235d74f5baa1a80ab9d74a0.gif" alt="" /></div>
</div>

<script>
let ctx = player.getContext('2d'),
      w = player.width = 350, h = player.height = 100,
      startX = 30, startY = 70, radius = 16,
      flag = false,
      color = { lrc: '#fa8c35', time: '#ffa631', track: '#eacd76', prg: 'red', circle: '#ffa631', btn: '#ca6924', btnhover: '#ca6924' };
      aud = new Audio();
let lrcAr = [
      ['1.90','心の跳動-FRESH_ye'],
        ['100.66','所属专辑:心の跳動'],
        ['120.07','谢谢欣赏']
];


aud.src = 'https://music.163.com/song/media/outer/url?id=1876206196.mp3';
aud.autoplay = true;
aud.loop = true;

drawBtn(aud.paused);
drawProgress(2, '00:00');
drawLrc('等待播放 ...');

let isHover = (x, y, cx, cy) => Math.pow(x - cx, 2) + Math.pow(y - cy, 2) <= Math.pow(radius, 2); //鼠标经过检测

player.addEventListener('mousemove', (e) => { //监听鼠标经过
      flag = isHover(e.offsetX, e.offsetY, startX, startY);
      if(flag) {
                player.style.cursor = 'pointer';
                drawBtn(aud.paused);
      } else {
                player.style.cursor = 'default';
                drawBtn(aud.paused);
      }
});

player.addEventListener('click', (e) => { if(flag) aud.paused ? aud.play() : aud.pause(); });

aud.addEventListener('playing',()=> drawBtn(false));
aud.addEventListener('pause',()=> drawBtn(true));

aud.addEventListener('timeupdate', () => { //进度监听
      let prg = 100 * aud.currentTime / aud.duration;
      drawProgress(2*prg, toMin(aud.duration) + ' | ' + toMin(aud.currentTime));
      for(j = 0; j < lrcAr.length;j ++) {
                if(aud.currentTime >= lrcAr) drawLrc(lrcAr);
      }
});

function drawLrc(text) { //lrc同步
      ctx.clearRect(0, 0, w, 50);
      ctx.save();
      ctx.fillStyle = color.lrc;
      ctx.textAlign = 'center';
      ctx.beginPath();
      ctx.font = '1.2em sans-serif';
      ctx.fillText(text, w/2, 30);
      ctx.fill();
      ctx.restore();
}

function drawProgress(prog, text) { //进度
      ctx.clearRect(startX + radius + 202, startY - 10, startX + radius + 206 + ctx.measureText(text).width, 40);
      ctx.beginPath();
      ctx.font = '14px sans-serif';
      ctx.textBaseline = 'middle';
      ctx.strokeStyle = color.track;
      ctx.moveTo(startX + radius + 4, startY);
      ctx.lineTo(startX + radius + 204, startY); //底线
      ctx.stroke();
      ctx.beginPath();
      ctx.strokeStyle = color.prg;
      ctx.moveTo(startX + radius + 4, startY);
      ctx.lineTo(startX + radius + 4 + prog, startY); //进度线
      ctx.stroke();
      ctx.fillStyle = color.time;
      ctx.fillText(text, startX + radius + 208, startY); //数字进度
      ctx.fill();
}

function drawBtn(id) { //绘制播放+暂停按钮
      ctx.clearRect(startX - radius, startY - radius, radius *2, radius*2);
      ctx.fillStyle = color.circle;
      ctx.beginPath();
      ctx.arc(startX, startY, radius, 0, 2*Math.PI);
      ctx.fill();
      ctx.fillStyle = flag ? color.btnhover : color.btn;
      ctx.beginPath();
      if (id) { //播放图标
                ctx.lineWidth = 1;
                ctx.moveTo(startX-radius / 2 + 1, startY - radius / 2);
                ctx.lineTo(startX - radius / 2 + 1, startY + radius / 2);
                ctx.lineTo(startX + radius / 2 + 1, startY);
                ctx.fill();
      } else { //暂停图标
                ctx.fillRect(startX - radius / 2 + 5, startY - radius / 2, 2, radius);
                ctx.fillRect(startX - radius / 2 + 10, startY - radius / 2, 2, radius);
      }
}

function toMin(val) {
      if(!val) return '00:00';
      val = Math.floor(val);
      let min = parseInt(val / 60);
      let sec = parseFloat(val % 60);
      if(min < 10) min = '0' + min;
      if(sec < 10) sec = '0' + sec;
      return min + ':' + sec;
}
</script>
页: 1 2 3 [4]
查看完整版本: 《生日快乐吗》- 陈思键 TO: 小辣椒