队长的雪谱
本帖最后由 马黑黑 于 2022-3-23 13:44 编辑<style type="text/css">
/* 帖子容器 */
#tzDiv {
position: relative;
left: -214px;
width: 1024px;
height: 600px;
top: 80px;
background: #eee url('https://pic.imgdb.cn/item/6237e66c27f86abb2ac15498.jpg') no-repeat center/cover;
opacity: 0.8;
}
/* 音乐控制按钮 */
.picBtn {
position: absolute;
width: 100px;
height: 100px;
left: 180px;
bottom: 60px;
border: none;
outline: none;
border-radius: 8px;
background: transparent url('http://image.hnol.net/c/2022-02/23/01/2022022301050291-5087368.gif') no-repeat;
cursor: pointer;
}
/* 文本时钟 */
#textClock {
position: absolute;
top: 180px;
right: 200px;
width: 300px;
height: 30px;
font: 20px / 30px Sans-Serif;
text-align: center;
}
/* 走马灯父框 */
.txtFly {
position: absolute;
width: 260px;
height: 30px;
right: 100px;
bottom: 100px;
overflow: hidden;
}
/* 走马灯文本 */
.txtFly div {
position: absolute;
left: 260px;
font: normal 18px /20px Sans-Serif;
word-break: keep-all;
white-space:nowrap;
}
/* 变色文本 */
.txtBg {
position: absolute;
top: 80px;
right: 100px;
font-size: 4rem;
color: transparent;
width: 500px;
height: 100px;
line-height: 100px;
text-align: center;
background-image: linear-gradient(90deg, green, olive, transparent, tomato, green);
background-size: 500px 100px;
background-position: 500px 0;
border: 1px solid;
background-clip: text;
-webkit-background-clip: text;
animation: chgc 2s linear infinite;
}
/* 文本变色动画 */
@keyframes chgc {
from { background-position: -500px 0; }
to { background-position: 0 0; }
}
</style>
<div id="tzDiv">
<div class="txtBg">雪谱</div>
<div id="textClock"></div>
<div class="txtFly">
<div id="ziFly">雪谱--寂悸一这张专辑表现出姫神独特的透明感,空灵唯美。 这是一首非常奇特的音乐,也许它并不十分的出色,但是对某些人,尤其处于生命中潜行的某个阶段中时,这段音乐对个人无疑有着极大的影响力。越是敏感的人,内心越是孤独的人,越是被容易感动。从自然入手,从唯美入心,然后才会被天地感动。</div>
</div>
<button id="picBtn" class="picBtn"></button>
<audio id="music" src="http://www.kumeiwp.com/sub/filestores/2022/03/21/48e0bb341096d2863debed1364767c45.mp3" loop="loop" autoplay="autoplay" ></audio>
</div>
<script language="javascript">
fly(); //运行走马灯
showTime(); //显示时间
setInterval(showTime, 1000); //运行时钟
//文本时钟函数
function showTime(){
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
var date = now.getDate();
var day = now.getDay();
var hour = now.getHours();
if(hour < 10) hour = "0" + hour;
var minute = now.getMinutes();
if(minute < 10) minute = "0" + minute;
var second = now.getSeconds();
if(second < 10) second = "0" + second;
document.getElementById("textClock").innerHTML = year + "年" + month + "月" + date + "日 星期" + toHz(day) + "" + hour + ":" + minute + ":" + second;
}
function toHz(num) { var hz = "日一二三四五六九"; return(hz.charAt(num)); }
//音乐控制代码
var mu = document.getElementById('music');
var btn = document.getElementById('picBtn');
btn.onclick = function(){
mu.paused ? (mu.play(), btn.style.background="url('http://image.hnol.net/c/2022-02/23/01/2022022301050291-5087368.gif')") : (mu.pause(), btn.style.background="url('http://image.hnol.net/c/2022-02/23/01/2022022301050291-5087368.gif')");
}
mu.addEventListener("ended", function(){
btn.style.background="url('http://image.hnol.net/c/2022-02/23/01/2022022301050291-5087368.gif')";
});
//创建走马灯
function fly() {
var ziFly = document.getElementById('ziFly');
var width = ziFly.clientWidth;
var style = document.createElement('style');
style.type = 'text/css';
var flyStr = '@keyframes fly {to { left: -' + width + 'px; } }';
style.innerHTML = flyStr;
ziFly.appendChild(style);
ziFly.style.animation = 'fly 40s linear infinite';
}
</script>
本帖最后由 马黑黑 于 2022-3-23 13:43 编辑 <br /><br /><style type="text/css">
/* 帖子容器 */
#tzDiv {
position: relative;
left: -214px;
width: 1024px;
height: 600px;
top: 80px;
background: #eee url('https://pic.imgdb.cn/item/6237e66c27f86abb2ac15498.jpg') no-repeat center/cover;
opacity: 0.8;
}
/* 音乐控制按钮 */
.picBtn {
position: absolute;
width: 100px;
height: 100px;
left: 180px;
bottom: 60px;
border: none;
outline: none;
border-radius: 8px;
background: transparent url('http://image.hnol.net/c/2022-02/23/01/2022022301050291-5087368.gif') no-repeat;
cursor: pointer;
}
/* 文本时钟 */
#textClock {
position: absolute;
top: 180px;
right: 200px;
width: 300px;
height: 30px;
font: 20px / 30px Sans-Serif;
text-align: center;
}
/* 走马灯父框 */
.txtFly {
position: absolute;
width: 260px;
height: 30px;
right: 100px;
bottom: 100px;
overflow: hidden;
}
/* 走马灯文本 */
.txtFly div {
position: absolute;
left: 260px;
font: normal 18px /20px Sans-Serif;
word-break: keep-all;
white-space:nowrap;
}
/* 变色文本 */
.txtBg {
position: absolute;
top: 80px;
right: 100px;
font-size: 4rem;
color: transparent;
width: 500px;
height: 100px;
line-height: 100px;
text-align: center;
background-image: linear-gradient(90deg, green, olive, transparent, tomato, green);
background-size: 500px 100px;
background-position: 500px 0;
border: 1px solid;
background-clip: text;
-webkit-background-clip: text;
animation: chgc 2s linear infinite;
}
/* 文本变色动画 */
@keyframes chgc {
from { background-position: -500px 0; }
to { background-position: 0 0; }
}
</style>
<div id="tzDiv">
<div class="txtBg">雪谱</div>
<div id="textClock"></div>
<div class="txtFly">
<div id="ziFly">雪谱--寂悸一这张专辑表现出姫神独特的透明感,空灵唯美。 这是一首非常奇特的音乐,也许它并不十分的出色,但是对某些人,尤其处于生命中潜行的某个阶段中时,这段音乐对个人无疑有着极大的影响力。越是敏感的人,内心越是孤独的人,越是被容易感动。从自然入手,从唯美入心,然后才会被天地感动。</div>
</div>
<button id="picBtn" class="picBtn"></button>
<audio id="music" src="http://www.kumeiwp.com/sub/filestores/2022/03/21/48e0bb341096d2863debed1364767c45.mp3" loop="loop" autoplay="autoplay" ></audio>
</div>
<script language="javascript">
fly(); //运行走马灯
showTime(); //显示时间
setInterval(showTime, 1000); //运行时钟
//文本时钟函数
function showTime(){
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
var date = now.getDate();
var day = now.getDay();
var hour = now.getHours();
if(hour < 10) hour = "0" + hour;
var minute = now.getMinutes();
if(minute < 10) minute = "0" + minute;
var second = now.getSeconds();
if(second < 10) second = "0" + second;
document.getElementById("textClock").innerHTML = year + "年" + month + "月" + date + "日 星期" + toHz(day) + "" + hour + ":" + minute + ":" + second;
}
function toHz(num) { var hz = "日一二三四五六九"; return(hz.charAt(num)); }
//音乐控制代码
var mu = document.getElementById('music');
var btn = document.getElementById('picBtn');
btn.onclick = function(){
mu.paused ? (mu.play(), btn.style.background="url('http://image.hnol.net/c/2022-02/23/01/2022022301050291-5087368.gif')") : (mu.pause(), btn.style.background="url('http://image.hnol.net/c/2022-02/23/01/2022022301050291-5087368.gif')");
}
mu.addEventListener("ended", function(){
btn.style.background="url('http://image.hnol.net/c/2022-02/23/01/2022022301050291-5087368.gif')";
});
//创建走马灯
function fly() {
var ziFly = document.getElementById('ziFly');
var width = ziFly.clientWidth;
var style = document.createElement('style');
style.type = 'text/css';
var flyStr = '@keyframes fly {to { left: -' + width + 'px; } }';
style.innerHTML = flyStr;
ziFly.appendChild(style);
ziFly.style.animation = 'fly 40s linear infinite';
}
</script>
代码整理、修改后不再是简单的拼凑,HTML代码逻辑增强,帖子整体布局容易入手。另,去掉已被废弃的 marquee 标签,用JS动态创建 @keyframes 动画,我有空会解释一下JS部分。
难度有二:
一是CSS代码偏多,这也没办法,帖子所需元素需要这些CSS的支撑。好在CSS各部分都管什么,都很明晰,基本可以看得出来。
二是JS部分。多数代码不用改动,但涉及到动画的部分,需要自己根据走马灯的文本多少去修改一下运行周期时长,本帖文本很长,所以用了 40 秒钟,JS的最后一行那里。 这个整理了全部代码,让代码变得清晰,并给出了非 marquee 标签的长文字的滚动代码,黑黑真棒{:4_187:} 滚动字和数字时钟的颜色也是在css中修改么? 红影 发表于 2022-3-23 17:19
滚动字和数字时钟的颜色也是在css中修改么?
对。这里,CSS负责样式,JS完成的主要是动作。 谢谢老黑整理。收藏了。{:4_190:} 加林森 发表于 2022-3-23 18:06
谢谢老黑整理。收藏了。
建议以后不再用 <center>、<font>、<marquee>这类已经被 w3c 组织废弃的HTML标签,同时建议学习整合 CSS、HTML、JS 代码,让代码流完整而不是切割开来。 马黑黑 发表于 2022-3-23 18:29
建议以后不再用 、、这类已经被 w3c 组织废弃的HTML标签,同时建议学习整合 CSS、HTML、JS 代码,让代码 ...
好的好的。一定记住了。{:4_190:} 马黑黑 发表于 2022-3-23 18:29
建议以后不再用 、、这类已经被 w3c 组织废弃的HTML标签,同时建议学习整合 CSS、HTML、JS 代码,让代码 ...
现在这个帖是全透明的了。{:4_190:} 马黑黑 发表于 2022-3-23 17:50
对。这里,CSS负责样式,JS完成的主要是动作。
恩,看到文字效果集中营里还有竖向滚动的,有这两个,滚动字的代码完备了{:4_187:} 红影 发表于 2022-3-23 19:25
恩,看到文字效果集中营里还有竖向滚动的,有这两个,滚动字的代码完备了
好像之前弄个纯CSS的,我再整理一下,让实现方式更简单 加林森 发表于 2022-3-23 19:13
现在这个帖是全透明的了。
准确滴说,是部分透明。全透明的话,你的图片一样都看不到 加林森 发表于 2022-3-23 19:08
好的好的。一定记住了。
{:5_108:} 马黑黑 发表于 2022-3-23 19:47
{:4_190:} 马黑黑 发表于 2022-3-23 19:47
准确滴说,是部分透明。全透明的话,你的图片一样都看不到
嗯嗯,你说的对。 先记下来。{:4_190:} 马黑黑 发表于 2022-3-23 19:46
好像之前弄个纯CSS的,我再整理一下,让实现方式更简单
好啊,其实那个逐行移动也有点这个效果呢。 红影 发表于 2022-3-23 22:19
好啊,其实那个逐行移动也有点这个效果呢。
嗯,但还可以逼真模拟 收藏学习 谢谢老黑{:4_204:}
页:
[1]
2