<html>
<head>
<style>
<!--
#leftright, #topdown{
position:absolute;
left:0;
top:0;
width:2px;
height:2px;
layer-background-color:#ff0000;
background-color:#ff0000;
z-index:500;
font-size:0px;
visibility:visible
}
-->
</style>
<title>坐标定位</title>
</head>
<BODY onmousemove="window.status='X='+window.event.x +'Y='+window.event.y"> 
<p align=center></a><p>
<script language="JavaScript">
<!--
//seawolf 2003-4-10
if (document.all&&!window.print){
leftright.style.width=document.body.clientWidth-6
topdown.style.height=document.body.clientHeight-1
}
else if (document.layers){
document.leftright.clip.width=window.innerWidth
document.leftright.clip.height=5
document.topdown.clip.width=5
document.topdown.clip.height=window.innerHeight
}
function followmouse1(){
//move cross engine for IE 4+
leftright.style.pixelTop=document.body.scrollTop+event.clientY-1///鼠标距坐标点位置
topdown.style.pixelTop=document.body.scrollTop
if (event.clientX<document.body.clientWidth-2)
topdown.style.pixelLeft=document.body.scrollLeft+event.clientX-1///鼠标距坐标点位置
else
topdown.style.pixelLeft=document.body.clientWidth-2
if(topdown.style.pixelLeft>500 ||leftright.style.pixelTop>550 )

topdown.style.visibility='hidden'
leftright.style.visibility='hidden'
}
else
{
topdown.style.visibility='visible'
leftright.style.visibility='visible'
}
}
function followmouse2(e){
//move cross engine for NS 4+
document.leftright.top=e.y+6
document.topdown.top=pageYOffset
document.topdown.left=e.x+6
}
if (document.all)
document.onmousemove=followmouse1
else if (document.layers){
window.captureEvents(Event.MOUSEMOVE)
window.onmousemove=followmouse2
}
function regenerate(){
window.location.reload()
}
function regenerate2(){
setTimeout("window.onresize=regenerate",400)
}
if ((document.all&&!window.print)||document.layers)
//if the user is using IE 4 or NS 4, both NOT IE 5+
window.onload=regenerate2
//-->
</script><div id="leftright" style="width:expression(document.body.clientWidth)"></div>
<div id="topdown" style="height:expression(document.body.clientHeight)"></div><img src="top.jpg" width=500 height=550> 坐标只在img的范围内显示
改了半天没该过来

解决方案 »

  1.   

    <html>
    <head>
    <style>
    <!--
    #leftright, #topdown{
    position:absolute;
    left:0;
    top:0;
    width:2px;
    height:2px;
    layer-background-color:#ff0000;
    background-color:#ff0000;
    z-index:500;
    font-size:0px;
    visibility:visible
    }
    -->
    </style>
    <title>坐标定位</title>
    </head>
    <BODY onmousemove="window.status='X='+window.event.x +'Y='+window.event.y"> 
    <p align=center></a><p>
    <script language="JavaScript">
    <!--
    //seawolf 2003-4-10
    if (document.all&&!window.print){
    leftright.style.width=document.body.clientWidth-6
    topdown.style.height=document.body.clientHeight-1
    }
    else if (document.layers){
    document.leftright.clip.width=window.innerWidth
    document.leftright.clip.height=5
    document.topdown.clip.width=5
    document.topdown.clip.height=window.innerHeight
    }
    function followmouse1(){
    //move cross engine for IE 4+
    leftright.style.pixelTop=document.body.scrollTop+event.clientY-1///鼠标距坐标点位置
    topdown.style.pixelTop=document.body.scrollTop
    if (event.clientX<document.body.clientWidth-2)
    topdown.style.pixelLeft=document.body.scrollLeft+event.clientX-1///鼠标距坐标点位置
    else
    topdown.style.pixelLeft=document.body.clientWidth-2
    if(document.all.m.width<event.clientX ||document.all.m.height<event.clientY || event.clientX<document.body.leftMargin||event.clientY<document.body.topMargin)

    topdown.style.visibility='hidden'
    leftright.style.visibility='hidden'
    }
    else
    {
    topdown.style.visibility='visible'
    leftright.style.visibility='visible'
    }
    }
    function followmouse2(e){
    //move cross engine for NS 4+
    document.leftright.top=e.y+6
    document.topdown.top=pageYOffset
    document.topdown.left=e.x+6
    }
    if (document.all)
    document.onmousemove=followmouse1
    else if (document.layers){
    window.captureEvents(Event.MOUSEMOVE)
    window.onmousemove=followmouse2
    }
    function regenerate(){
    window.location.reload()
    }
    function regenerate2(){
    setTimeout("window.onresize=regenerate",400)
    }
    if ((document.all&&!window.print)||document.layers)
    //if the user is using IE 4 or NS 4, both NOT IE 5+
    window.onload=regenerate2
    //-->
    </script><div id="leftright" style="width:expression(document.body.clientWidth)"></div>
    <div id="topdown" style="height:expression(document.body.clientHeight)"></div><img src="top.jpg" width=500 height=550 id=m> 坐标只在img的范围内显示