以下代码实现图片跟随鼠标的功能。可是点击链接是就是不行,在IE里可以实现,可是在遨游里就不可以。求原因或修改方法。<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>网页特效|JsCode.cn|---跟随鼠标的图片</title>
<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>
</head>
<body>
<!-- 以下代码是设定此页的鼠标样式代码 -->
<script language="javascript">
if (navigator.appName == "Netscape") {
}
else
{
document.write('<div ID=OuterDiv>')
document.write('<img ID=iit src="http://fgtt.bokee.com/inc/logo_s.png" STYLE="position:absolute;TOP:5pt;LEFT:5pt;Z-INDEX:10;visibility:hidden;">')
document.write('</div>')
}
</script>
<a href="http://www.baidu.com">百度
</a>
</body>
</html>

解决方案 »

  1.   

    搞定!<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>网页特效|JsCode.cn|---跟随鼠标的图片</title>
    <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+100
    }
    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>
    </head>
    <body>
    <!-- 以下代码是设定此页的鼠标样式代码 -->
    <script language="javascript">
    if (navigator.appName == "Netscape") {
    }
    else
    {
    document.write('<div ID=OuterDiv>')
    document.write('<img ID=iit src="http://fgtt.bokee.com/inc/logo_s.png" STYLE="position:absolute;TOP:5pt;LEFT:5pt;Z-INDEX:10;visibility:hidden;">')
    document.write('</div>')
    }
    </script>
    <a href="http://www.baidu.com">百度
    </a>
    </body>
    </html>
    原因是找到了,就是在傲游下的时候图片偏移到了鼠标底下盖住了鼠标,在代码红色部分我给他整了个100,有点夸张,你可以改个5或者10为什ie和傲游有差距我不清楚~难道这也存在兼容问题?傲游是最接近 ie的了!
      

  2.   

    搞定!<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>网页特效|JsCode.cn|---跟随鼠标的图片</title>
    <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+100
    }
    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>
    </head>
    <body>
    <!-- 以下代码是设定此页的鼠标样式代码 -->
    <script language="javascript">
    if (navigator.appName == "Netscape") {
    }
    else
    {
    document.write('<div ID=OuterDiv>')
    document.write('<img ID=iit src="http://fgtt.bokee.com/inc/logo_s.png" STYLE="position:absolute;TOP:5pt;LEFT:5pt;Z-INDEX:10;visibility:hidden;">')
    document.write('</div>')
    }
    </script>
    <a href="http://www.baidu.com">百度
    </a>
    </body>
    </html>
    真晕,这论坛不会玩,想高个亮没办到~直接贴源代码注意我改了你代码中的这一句:
    newleft=document.body.scrollLeft + event.clientX+100
    ==================================
    顺便再试试高亮newleft=document.body.scrollLeft + event.clientX+100