文字跟随鼠标代码怎么弄的?
3个回答
2013-10-30
展开全部
把下列代码加入<head>……</head>中:
<script>
var x,y
var step=20
var flag=0
// Your snappy message. 注意最后一个空格!!!
var message="您好,谢谢使用本实例教程! " //输入想要跟随的文字
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
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]
}
}
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]
}
}
var timer=setTimeout("makesnake()",30)
}
</script>
把下列代码加入<body onLoad="makesnake()">……</body>中:
<script>
for (i=0;i<=message.length;i++) {
document.write("<span id='span"+i+"' class='mark'>")
document.write(message[i])
document.write("</span>")
}
if (document.layers){
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = handlerMM;
</script>
加入下列CSS样式到<head>……</head>中:
<STYLE>.mark {
FONT-WEIGHT: bold; FONT-SIZE: 10pt; VISIBILITY: visible; COLOR: black; FONT-FAMILY: Verdana; POSITION: absolute; TOP: -50px
}
</STYLE>
<script>
var x,y
var step=20
var flag=0
// Your snappy message. 注意最后一个空格!!!
var message="您好,谢谢使用本实例教程! " //输入想要跟随的文字
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
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]
}
}
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]
}
}
var timer=setTimeout("makesnake()",30)
}
</script>
把下列代码加入<body onLoad="makesnake()">……</body>中:
<script>
for (i=0;i<=message.length;i++) {
document.write("<span id='span"+i+"' class='mark'>")
document.write(message[i])
document.write("</span>")
}
if (document.layers){
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = handlerMM;
</script>
加入下列CSS样式到<head>……</head>中:
<STYLE>.mark {
FONT-WEIGHT: bold; FONT-SIZE: 10pt; VISIBILITY: visible; COLOR: black; FONT-FAMILY: Verdana; POSITION: absolute; TOP: -50px
}
</STYLE>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-10-30
展开全部
这是一个跟随彩色文字的特效
<STYLE>.spanstyle{COLOR: #0066ff; FONT-FAMILY: 宋体;FONT-SIZE:9pt;FONT-WEIGHT:normal;POSITION:absolute;TOP:-50px;VISIBILITY:visible}</STYLE>
<SCRIPT><script>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>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>function pageonload(){makesnake();window.setTimeout("pageonload();", 2);}</SCRIPT>
<SCRIPT>pageonload()</SCRIPT>
<STYLE>.spanstyle{COLOR: #0066ff; FONT-FAMILY: 宋体;FONT-SIZE:9pt;FONT-WEIGHT:normal;POSITION:absolute;TOP:-50px;VISIBILITY:visible}</STYLE>
<SCRIPT><script>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>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>function pageonload(){makesnake();window.setTimeout("pageonload();", 2);}</SCRIPT>
<SCRIPT>pageonload()</SCRIPT>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-10-30
展开全部
至于那些字的颜色我认为你很容易就能搞定的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询