HTML鼠标跟踪彩虹文字

这篇博客介绍了如何使用HTML和JavaScript实现鼠标跟踪的彩虹文字效果。通过设置样式并在JavaScript中处理鼠标移动事件,动态更新文字的位置和颜色,创建出一种跟随鼠标的视觉效果。此外,还展示了获取当前日期和时间的JavaScript代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一步骤 :
在<head></head>中加入如下代码:<STYLE>.spanstyle {
COLOR: #0066ff; FONT-FAMILY: 宋体; FONT-SIZE: 12pt; FONT-WEIGHT: normal; POSITION: absolute; TOP: -50px; VISIBILITY: visible
}
</STYLE>

第二步骤 :
在<body>中加入如下代码:<body onload="javascript:pageonload()" bgcolor="#000000">

第三步骤 :
在<body></body>中加入如下代码:<script language=javascript>
var message="冰 海 家 园 网 页 制 作 技 巧 资 源 网 站";
var x,y;
var step=12;
var flag=0;
message=message.split("");
var xpos=new Array();
for (i=0;i<=message.length-1;i++) {
xpos[i]=-50;
}
var ypos=new Array();
for (i=0;i<=message.length-1;i++) {
ypos[i]=-50;
}
function handlerMM(e) {
x = (document.layers) ? e.pageX : document.body.scrollLeft+event.clientX+10;
y = (document.layers) ? e.pageY : document.body.scrollTop+event.clientY;
flag=1;
}
function makesnake() {
if (flag==1 && document.all) {
for (i=message.length-1; i>=1; i--) {
xpos[i]=xpos[i-1]+step;
ypos[i]=ypos[i-1];
}
xpos[0]=x+step;
ypos[0]=y;
for (i=0; i<=message.length-1; i++) {
var thisspan = eval("span"+(i)+".style");
thisspan.posLeft=xpos[i];
thisspan.posTop=ypos[i];
thisspan.color=Math.random() * 255 * 255 * 255 + Math.random() * 255 * 255 + Math.random() * 255;
}
}
else if (flag==1 && document.layers) {
for (i=message.length-1; i>=1; i--) {
xpos[i]=xpos[i-1]+step;
ypos[i]=ypos[i-1];
}
xpos[0]=x+step;
ypos[0]=y;
for (i=0; i<message.length-1; i++) {
var thisspan = eval("document.span"+i);
thisspan.left=xpos[i];
thisspan.top=ypos[i];
thisspan.color=Math.random() * 255 * 255 * 255 + Math.random() * 255 * 255 + Math.random() * 255;
}
}
}
</script>
<script language=javascript>
for (i=0;i<=message.length-1;i++) {
document.write("<span id='span"+i+"' class='spanstyle'>");
document.write(message[i]);
document.write("</span>");
}
if (document.layers) {
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = handlerMM;
</script>
<script language=javascript>
function pageonload() {
makesnake();
window.setTimeout("pageonload();", 2);
}
</script>

 


riqi

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function Year_Month(){
var now = new Date();
var yy = now.getYear();
var mm = now.getMonth()+1;
var cl = '<font color="#000000">';
return(cl +yy + '年' + mm + '月</font>');
}function Date_of_Today(){
var now = new Date();
var cl = '<font color="#000000"><b>';
if (now.getDay() == 0) cl = '<font color="#FF0000"><b>';
if (now.getDay() == 6) cl = '<font color="#008000"><b>';
return(cl +now.getDate() + '</font></b>');
}function Day_of_Today(){
var day = new Array();
day[0] = "星期日";
day[1] = "星期一";
day[2] = "星期二";
day[3] = "星期三";
day[4] = "星期四";
day[5] = "星期五";
day[6] = "星期六";
var now = new Date();
var cl = '<font color="#000000">';
if (now.getDay() == 0) cl = '<font color="#FF0000">';
if (now.getDay() == 6) cl = '<font color="#008000">';
return(cl +day[now.getDay()] + '</font>');
}function CurentTime(){
var now = new Date();
var hh = now.getHours();
var mm = now.getMinutes();
var ss = now.getTime() % 60000;
ss = (ss - (ss % 1000)) / 1000;
var clock = hh+':';
if (mm < 10) clock += '0';
clock += mm+':';
if (ss < 10) clock += '0';
clock += ss;
return(clock);
}function refreshCalendarClock(){
document.all.calendarClock1.innerHTML = Year_Month();
document.all.calendarClock2.innerHTML = Date_of_Today();
document.all.calendarClock3.innerHTML = Day_of_Today();
document.all.calendarClock4.innerHTML = CurentTime();
}document.write('<table border="0" cellpadding="0" cellspacing="0" width="70" bgcolor="#C0C0C0" height="65">');
document.write('<tr><td valign="top" width="100%" height="100%">');
document.write('<table border="1" bordercolor="#993300" cellpadding="0" cellspacing="0" width="70" bgcolor="#FFFF99" height="65">');
document.write('<tr><td align="center" width="100%" height="100%" >');
document.write('<font id="calendarClock1" style="font-family:宋体;font-size:9pt;line-height:120%"> </font><br>');
document.write('<font id="calendarClock2" style="font-family:Arial;font-size:18pt;line-height:120%"> </font><br>');
document.write('<font id="calendarClock3" style="font-family:宋体;font-size:9pt;line-height:120%"> </font><br>');
document.write('<font id="calendarClock4" style="color:#000000;font-family:宋体;font-size:9pt;line-height:120%"><b> </b></font>');
document.write('</td></tr></table>');
document.write('</td></tr></table>');
refreshCalendarClock()
setInterval('refreshCalendarClock()',1000);
// End -->
</SCRIPT>


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值