空中散步
<style>#papa { left: -214px; width: 1024px; height: 640px; box-shadow: 4px 4px 30px #000; border-radius: 6px; overflow: hidden; position: relative; }
#mama {position: absolute; width: inherit; height: inherit; left: 0; top: -640px; background: #ccc url('https://638183.freep.cn/638183/t22/hl/kong.jpg') no-repeat center / cover; }
#mama input { border: none; outline: none; opacity: .75; cursor: pointer; }
#mama p { margin: 0; padding: 0; }
.playbox { position: absolute; left: 10px; top: 10px; padding: 10px; font: normal 1em sans-serif; color: #eee; background: rgba(255,255,255,.2); border-radius: 8px; backdrop-filter: blur(1px); overflow: hidden; box-shadow: 1px 1px 2px rgba(0,0,0,.15); z-index: 100; }
#btnplay { width: 30px; height: 30px; border-radius: 50%; }
#btnplay:hover { background: #aaa; color: #ff0000; }
#papa > img { position: absolute; border: none; outline: none; }
#ufo2 { left: 0; top: 0; width: 64px; height: 80px; transition: all 2s; }
#tang1 { top: 520px; width: 120px; height: 120px; opacity: .2; cursor: pointer; }
@keyframes up { to { transform: translateY(-700px); } }
@keyframes down { to { top: 0px; } }
</style>
<div id="papa">
<img id="ufo2" src="https://638183.freep.cn/638183/t22/hl/ufo2.gif" alt="" />
<img id="tang1" src="https://638183.freep.cn/638183/t22/hl/tang1.gif" alt="" />
<div id="mama">
<div class="playbox">
<p id="geci" style="font-size: 1.2em; text-shadow: 1px 1px 1px #222">stand by ... </p>
<p style="display: flex; align-items: center; gap: 4px; margin-top: 10px;">
<input id="btnplay" type="button" value=">" />
<input id="slider" type="range" min="0" max="100" value="0" />
<span id="per">0%</span>
</p>
</div>
</div>
</div>
<audio id="aud" src="https://music.163.com/song/media/outer/url?id=442488.mp3" loop="loop"></audio>
<script>
let lrcAr = [ ['0.00','纯音乐 - 空中散步'], ['120.00','没有音乐人生将与精彩无缘'] ];
let num = (min, max) => Math.floor(Math.random() * (max-min+1)) + min;
tang1.style.left = num(0,924) + 'px';
ufo2.style.left = num(0,924) + 'px';
tang1.onclick = () => {
tang1.style.opacity = 1;
ufo2.style.left = tang1.offsetLeft+ 30 + 'px';
ufo2.style.top = tang1.offsetTop - 60 + 'px';
setTimeout(() => {
ufo2.style.animation = tang1.style.animation = 'up 4s forwards';
},2200);
setTimeout(() => {
mama.style.animation = 'down 4s forwards';
aud.play();
},4300);
}
slider.onmousedown = () => aud.pause();
slider.onchange = () => { aud.currentTime = slider.value * aud.duration / 100; aud.play(); }
btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
aud.addEventListener('playing', () => btnplay.value = '||');
aud.addEventListener('pause', () => btnplay.value = '>');
aud.addEventListener('timeupdate', () => {
let prog = 100 * aud.currentTime / aud.duration;
slider.value = prog;
per.innerText = toMin(aud.currentTime) + ' | ' + toMin(aud.duration);
for(j=0; j<lrcAr.length; j++){
if(aud.currentTime >= lrcAr) geci.innerHTML = lrcAr;
}
});
let toMin = (val) => {
if(!val) return '0:0';
val = Math.floor(val);
return parseInt(val / 60) + ':' +parseFloat(val % 60);
}
</script>
马黑黑 发表于 2022-7-14 18:17
学学就会。人家东篱还会骑驴走四方。
我就看你飞。 代码:
<style>
#papa { left: -214px; width: 1024px; height: 640px; box-shadow: 4px 4px 30px #000; border-radius: 6px; overflow: hidden; position: relative; }
#mama {position: absolute; width: inherit; height: inherit; left: 0; top: -640px; background: #ccc url('https://638183.freep.cn/638183/t22/hl/kong.jpg') no-repeat center / cover; }
#mama input { border: none; outline: none; opacity: .75; cursor: pointer; }
#mama p { margin: 0; padding: 0; }
.playbox { position: absolute; left: 10px; top: 10px; padding: 10px; font: normal 1em sans-serif; color: #eee; background: rgba(255,255,255,.2); border-radius: 8px; backdrop-filter: blur(1px); overflow: hidden; box-shadow: 1px 1px 2px rgba(0,0,0,.15); z-index: 100; }
#btnplay { width: 30px; height: 30px; border-radius: 50%; }
#btnplay:hover { background: #aaa; color: #ff0000; }
#papa > img { position: absolute; border: none; outline: none; }
#ufo2 { left: 0; top: 0; width: 64px; height: 80px; transition: all 2s; }
#tang1 { top: 520px; width: 120px; height: 120px; opacity: .2; cursor: pointer; }
@keyframes up { to { transform: translateY(-700px); } }
@keyframes down { to { top: 0px; } }
</style>
<div id="papa">
<img id="ufo2" src="https://638183.freep.cn/638183/t22/hl/ufo2.gif" alt="" />
<img id="tang1" src="https://638183.freep.cn/638183/t22/hl/tang1.gif" alt="" />
<div id="mama">
<div class="playbox">
<p id="geci" style="font-size: 1.2em; text-shadow: 1px 1px 1px #222">stand by ... </p>
<p style="display: flex; align-items: center; gap: 4px; margin-top: 10px;">
<input id="btnplay" type="button" value=">" />
<input id="slider" type="range" min="0" max="100" value="0" />
<span id="per">0%</span>
</p>
</div>
</div>
</div>
<audio id="aud" src="https://music.163.com/song/media/outer/url?id=442488.mp3" loop="loop"></audio>
<script>
let lrcAr = [ ['0.00','纯音乐 - 空中散步'], ['120.00','没有音乐人生将与精彩无缘'] ];
let num = (min, max) => Math.floor(Math.random() * (max-min+1)) + min;
tang1.style.left = num(0,924) + 'px';
ufo2.style.left = num(0,924) + 'px';
tang1.onclick = () => {
tang1.style.opacity = 1;
ufo2.style.left = tang1.offsetLeft+ 30 + 'px';
ufo2.style.top = tang1.offsetTop - 60 + 'px';
setTimeout(() => {
ufo2.style.animation = tang1.style.animation = 'up 4s forwards';
},2200);
setTimeout(() => {
mama.style.animation = 'down 4s forwards';
aud.play();
},4300);
}
slider.onmousedown = () => aud.pause();
slider.onchange = () => { aud.currentTime = slider.value * aud.duration / 100; aud.play(); }
btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
aud.addEventListener('playing', () => btnplay.value = '||');
aud.addEventListener('pause', () => btnplay.value = '>');
aud.addEventListener('timeupdate', () => {
let prog = 100 * aud.currentTime / aud.duration;
slider.value = prog;
per.innerText = toMin(aud.currentTime) + ' | ' + toMin(aud.duration);
for(j=0; j<lrcAr.length; j++){
if(aud.currentTime >= lrcAr) geci.innerHTML = lrcAr;
}
});
let toMin = (val) => {
if(!val) return '0:0';
val = Math.floor(val);
return parseInt(val / 60) + ':' +parseFloat(val % 60);
}
</script>
帖子开头部分,使用一个简单的交互机制,且称之为“序章”。
本帖序章的创意来自一念之间:眼见一只小鸟在水面抓鱼,瞬间掠过水面,瞬间升空。我就想,我要做个普普通通的音乐帖,用水面上的猎杀场景——当然是要改装过的——做起头部分。
然后就有了这一帖。 本帖的交互,需要一个单击操作:初始页面上的两个元素,有一个是手型鼠标指针,单击它,序章开启…… 序章之后,帖子不再提供其它交互,除了播放器 这个创意有意思。赞! 空中跳舞开始了。 本帖最后由 山人 于 2022-7-14 07:55 编辑
初始时,底部图片的单击事件代码,
tang1.onclick = () => {
tang1.style.opacity = 1;
ufo2.style.left = tang1.offsetLeft+ 30 + 'px';
ufo2.style.top = tang1.offsetTop - 60 + 'px';
setTimeout(() => {
ufo2.style.animation = tang1.style.animation = 'up 4s forwards';
},2200);
setTimeout(() => {
mama.style.animation = 'down 4s forwards';
aud.play();
},4300);
}
先是将前面CSS定义的 opacity 改为 1,恢复老唐帅气十足的真容。接着设置ufo的left和top,令其从上而下,其运行速率依赖CSS中的 transition 设置;left和top值的具体设定都是通过心算而得,依据的是底部图片的位置及其两图的尺寸。
接着就略微复杂一些,用了两个setTimeout定时器:
第一个定时器:到点时执行两张图片的离场关键帧动画 up,用时4秒,定时器间隔时长则是2.2秒,这是加上了 transition 时长 2 秒并预留一点点;
第二个定时器:定时器周期4.3秒,这是前面定时器和transition用时总和再略加一点而得。该定时器到点后执行 mama 元素出场的关键帧动画 down,华丽的出场用时也是4秒。mama虽轻装简出但拖儿带女,在华美的乐章奏起的同时徐徐移步,简朴而亮丽……
挺会玩。。。{:4_170:} 原来一定要等唐僧被妖怪抓走了,音乐才开始呈现{:4_173:} 马黑黑 发表于 2022-7-14 07:15
帖子开头部分,使用一个简单的交互机制,且称之为“序章”。
本帖序章的创意来自一念之间:眼见一只小鸟 ...
遇到什么都能想到用代码去实现,而且能实现,黑黑真厉害{:4_199:} 不如让那妖怪去抓几个大美女进音乐厅陪大家一起边听边跳多好。{:4_173:} 樵歌 发表于 2022-7-14 09:15
不如让那妖怪去抓几个大美女进音乐厅陪大家一起边听边跳多好。
好主意,叫东篱来处理 好玩,进来等一会,原来是要点唐僧才能听到音乐看到图片 {:4_187:}老黑真棒!好创意!
{:4_204:}{:4_191:}{:4_179:} 大猫咪 发表于 2022-7-14 12:27
好玩,进来等一会,原来是要点唐僧才能听到音乐看到图片 老黑真棒!好创意!
{:4_191 ...
{:4_172:} 红影 发表于 2022-7-14 09:04
遇到什么都能想到用代码去实现,而且能实现,黑黑真厉害
生活就是有代码构建的,俺只是有限还原 加林森 发表于 2022-7-14 07:34
这个创意有意思。赞!
可以玩玩吧 加林森 发表于 2022-7-14 07:37
空中跳舞开始了。
队长跳个 东篱闲人 发表于 2022-7-14 08:16
挺会玩。。。
玩玩更快乐 红影 发表于 2022-7-14 08:59
原来一定要等唐僧被妖怪抓走了,音乐才开始呈现
可以玩玩吧?