怎样制作网页中的字跟着鼠标走呀?????

怎样制作网页中的字跟着鼠标走呀?????,第1张

分类: 电脑/网络 >>互联网

问题描述:

代码给我发上呀,谢谢

解析:

*让字跟着鼠标走源代码:(把下面的代码插入到body区域中)

<script language="JavaScript">

<!--

/****** Things you can change *****/

msg="梦幻岛"

msgSize=41-7

FoNt='Arial'

CoLoR='#CC99FF'

speed=2

/****** Things you shouldn't change *****/

ns=(documentyers)?1:0

msg=msg.split(''),amount=msg.length,Y=0,X=0,ypos=0,xpos=0,ybase=new Array(),xbase=new Array()

angle = new Array(),divTop= new Array(),divLeft=new Array()

DocHeight=(documentyers)?window.innerHeight:window.document.body.offsetHeight

DocWidth=(documentyers)?window.innerWidth:window.document.body.offsetWidth

initial layer placement!

for (i=0i <amounti++){

divTop[i]=Math.round(Math.random()*DocHeight)

divLeft[i]=Math.round(Math.random()*DocWidth)

}

if (ns){

for (i = 0i <amounti++)

{document.write('<layer name=nsd'+i+' top=0 left=0 width='+msgSize+' height='+msgSize+'><font face='+FoNt+' size='+msgSize+' color='+CoLoR+'>'+msg[i]+'</font></layer>')}

window.captureEvents(Event.MOUSEMOVE)

function nsMouse(evnt){

ypos = evnt.pageY-20

xpos = evnt.pageX-10

}

window.onMouseMove = nsMouse

}

else{

document.write('<div id="hldr" class="page_speeder_1556124594">')

document.write('<div class="page_speeder_1586183728">')

for (i=0i <amounti++)

{document.write('<div id=ied class="page_speeder_968996550"><font face='+FoNt+' size='+msgSize+' color='+CoLoR+'>'+msg[i]+'</font></div>')}

document.write('</div></div>')

function ieMouse(){

ypos = event.y-20

xpos = event.x-10

}

document.onmousemove = ieMouse

}

function GoToMouse(){

var DocHeight=(documentyers)?window.innerHeight:window.document.body.offsetHeight

var DocWidth=(documentyers)?window.innerWidth:window.document.body.offsetWidth

var iscrll=(document.all)?document.body.scrollTop:0

var nscrll=(documentyers)?window.pageYOffset:0

if (!ns)hldr.style.top=iscrll

for (i=0i <amounti++){

Y = ypos - divTop[i]

X = xpos - divLeft[i]

angle[i] = Math.round(Math.atan2(Y,X) * 180/Math.PI)

if (angle[i] <0) angle[i] += 360

ybase[i]=Math.round(Math.random()*DocHeight)

xbase[i]=Math.round(Math.random()*DocWidth)

rep=Math.round(Math.random() * 3)

extra=Math.round(Math.random() * 200)

if (rep == 3)xbase[i] =-extra

if (rep == 2)xbase[i] =DocWidth+extra

if (rep == 1)ybase[i] =-extra

if (rep == 0)ybase[i] =DocHeight

y = Math.round(speed*Math.sin(angle[i]*Math.PI/180))

x = Math.round(speed*Math.cos(angle[i]*Math.PI/180))

divTop[i]+=y

divLeft[i]+=x

if ((divLeft[i] >xpos-speed) &&(divLeft[i] <xpos+speed/1.5) &&(divTop[i] >= ypos-speed/1.5) &&(divTop[i] <= ypos+speed/1.5))

{divTop[i]=ybase[i]+nscrlldivLeft[i]=xbase[i]}

var layer=(documentyers)?documentyers['nsd'+i]:ied[i].style

layer.top=divTop[i]layer.left=divLeft[i]

}

S=setTimeout('GoToMouse()',10)

}

window.onload=GoToMouse

-->

</script>

脚本说明:

第一步:把如下代码加入<body>区域中

<SCRIPT LANGUAGE="JavaScript">

var newtop=0

var newleft=0

if (navigator.appName == "Netscape") {

layerStyleRef="layer."

layerRef="document.layers"

styleSwitch=""

}

else

{

layerStyleRef="layer.style."

layerRef="document.all"

styleSwitch=".style"

}

function doMouseMove() {

layerName = 'iit'

eval('var curElement='+layerRef+'["'+layerName+'"]')

eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"')

eval('curElement'+styleSwitch+'.visibility="visible"')

eval('newleft=document.body.clientWidth-curElement'+styleSwitch+'.pixelWidth')

eval('newtop=document.body.clientHeight-curElement'+styleSwitch+'.pixelHeight')

eval('height=curElement'+styleSwitch+'.height')

eval('width=curElement'+styleSwitch+'.width')

width=parseInt(width)

height=parseInt(height)

if (event.clientX >(document.body.clientWidth - 5 - width))

{

newleft=document.body.clientWidth + document.body.scrollLeft - 5 - width

}

else

{

newleft=document.body.scrollLeft + event.clientX

}

eval('curElement'+styleSwitch+'.pixelLeft=newleft')

if (event.clientY >(document.body.clientHeight - 5 - height))

{

newtop=document.body.clientHeight + document.body.scrollTop - 5 - height

}

else

{

newtop=document.body.scrollTop + event.clientY

}

eval('curElement'+styleSwitch+'.pixelTop=newtop')

}

document.onmousemove = doMouseMove

</SCRIPT>

第二步:把如下代码加入<body>区域中

<script language="javascript">

if (navigator.appName == "Netscape") {

}

else

{

document.write('<div ID=OuterDiv>')

document.write('<img ID=iit src="image1.gif" STYLE="position:absoluteTOP:0ptLEFT:0ptwidth=103height=28Z-INDEX:2visibility:hidden">')

document.write('</div>')

}

</script>


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11206045.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-14
下一篇2023-05-14

发表评论

登录后才能评论

评论列表(0条)

    保存