js鼠标跟随

<html>

<head><title>鼠标跟随</title>

<!--

var newtop=0;

var newleft=0;

if(navigator.appName=="Netscape")/*对于Netscape浏览器-网景浏览器,在和微软的竞争中退出市场,由于网景浏览器的代码是开源的,最近挺多出名的浏览器,例如360浏览器都由其制作*/

{

layerStyleRef="layer.";

layerRef="document.layers";

styleSwitch="";

}

else// IE浏览器

{

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)

//设置图片的x坐标:将其与鼠标位置坐标绑定

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‘)
//设置图片的y坐标:将其与鼠标位置坐标绑定

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 = helpor_net;//调用doMouseMove函数

</script>

</head>

<body>

<center><h1>图片随鼠标移动实例</h1>

<!--以下代码设定此页鼠标样式-->

<script language="text/javascript">

<!--

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

else

{

document.write(‘<div ID=OuterDiv>‘);

document.write(‘<img ID=iit src="name.gif" STYLE="position:absolute;TOP:5pt;LEFT:5pt;ZINDEX:10;visibility:hidden;">‘);

document.write(‘</div>‘)

}

//-->

</script>

</body>

</html>

js鼠标跟随,布布扣,bubuko.com

js鼠标跟随

上一篇:.net自定义事件,经典简单实例代码


下一篇:微软Asp.net MVC5生命周期流程图