|
|

楼主 |
发表于 2023-6-8 20:58
|
显示全部楼层
帖子代码
- <css-doodle grid="1x6" id="papa">
- :doodle {
- @size: 900px 598px;
- background: url('https://638183.freep.cn/638183/t23/2/dadi.jpg');
- box-shadow: 0 0 8px #000;
- position: relative;
- margin: 0 0 0 calc(50% - 531px);
- z-index: 1;
- --ww: 300px; /* 进度条总长 */
- --prog: 0; /* 进度 */
- --tt1: '00:00'; /* 当前播放时间 */
- --tt2: '00:00'; /* 音乐时长 */
- --xplace: 50%; /* 播放器水平定位 */
- --yplace: 98%; /* 播放器垂直定位 */
- --color: snow;
- --state: paused; /* 关键帧运行状态 */
- }
- /* 单元格1 :进度条 */
- @nth(1) {
- @size: var(--ww) 2px;
- @place: var(--xplace) var(--yplace);
- background: silver;
- :before, :after { content: ''; }
- :before {
- position: absolute;
- left: 0;
- width: var(--prog);
- height: 100%;
- background: var(--color);
- }
- :after {
- width: 100%;
- height: 10px;
- cursor: pointer;
- }
- }
- /* 单元格2 :播放时间信息 */
- @nth(2) {
- @size: var(--ww) 20px;
- @place: var(--xplace) calc(var(--yplace) - 20px);
- :before, :after{
- position: absolute;
- width: 100%;
- height: 100%;
- color: var(--color);
- }
- :before { content: var(--tt1); }
- :after { content: var(--tt2); text-align: right; }
- }
- /* 单元格3和4 :播放按钮 */
- @nth(3,4) {
- @size: 60px;
- @place: var(--xplace) calc(var(--yplace) - 36px);
- cursor: pointer;
- }
- @nth(3) {
- @size: 50px;
- @shape: clover 4;
- background: var(--color);
- animation: rot 6s infinite linear var(--state);
- }
- @match(i ≥ 5) {
- @size: 100px 88px;
- @place: 50px 44px;
- background: url('https://638183.freep.cn/638183/t22/gif/ying1.gif');
- offset-path: path('M50 44 Q500 300 900 44');
- offset-distance: 0%;
- animation: fly 10s calc(@r(1,10) * -1s) infinite linear var(--state);
- }
- @keyframes rot { to { transform: rotate(360deg); } }
- @keyframes fly { to { offset-distance: 100%; }}
- </css-doodle>
- <audio id="aud" src="https://music.163.com/song/media/outer/url?id=438980" autoplay="autoplay" loop="loop"></audio>
- <script>
- (function(){
- let script = document.createElement('script');
- script.src = 'https://638183.freep.cn/638183/web/api/css-doodle.js';
- document.head.appendChild(script);
- 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;};
- let mState = () => papa.style.setProperty('--state', aud.paused ? 'paused' : 'running');
- aud.addEventListener('timeupdate', () => {
- papa.style.setProperty('--prog', 100*aud.currentTime/aud.duration + '%');
- papa.style.setProperty('--tt1', `'${toMin(aud.currentTime)}'`);
- papa.style.setProperty('--tt2', `'${toMin(aud.duration)}'`);
- });
- aud.addEventListener('play', mState, false);
- aud.addEventListener('pause', mState, false);
- window.onload = () => {
- let btns = papa.shadowRoot.querySelectorAll('cell');
- let ww = parseInt(window.getComputedStyle(papa).getPropertyValue('--ww'));
- btns[3].onclick = () => aud.paused ? aud.play() : aud.pause();
- btns[0].onclick = (e) => aud.currentTime = e.offsetX * aud.duration / ww;
- }
- })();
- </script>
复制代码
|
评分
-
| 参与人数 1 | 威望 +50 |
金钱 +100 |
经验 +50 |
收起
理由
|
红影
| + 50 |
+ 100 |
+ 50 |
赞一个! |
查看全部评分
|