你要加上document.body.scrollLeft和document.body.scrollTop就可以了。

解决方案 »

  1.   

    你是怎么定位置的?
    是不是设置的style.left和style.top
    当鼠标经过那个关键字的时候,就是说触发了onmouseover事件,然后获取鼠标的位置。。
    然后让鼠标的位置加上document.body.scrollLeft、document.body.scrollTop即就是这个关键子在网页中的位置。
    这里有个window的特效你可以简单看下。
    http://community.csdn.net/Expert/topic/5283/5283616.xml?temp=.7460749
      

  2.   

    我是这样子弄的:当onclick关键字的时候用ajax调用数据,然后显示到这个层里面,就是出现滚动条的时候,这个层的位置不准确了.
    function tagshow(varVal){
    data_win.style.top=window.event.y+"px";
    data_win.style.left=window.event.x+"px";
    data_win.style.display = "block";
    voucharTip = document.getElementById("data_win");
        totaourl = "../ajaxCheck.php?method=gettag&tag="+encodeURIComponent(varVal)+"&now=" + new Date().getTime();
        send_request(totaourl);
    }<div id="data_win" style="display: none;position:absolute;"></div>页面上没有滚动条是正确的,就在关键字右下角,有滚动条就不对了.
     就是这个http://www.sales007.com/news/detail-1-0.html样子,不会改了
      

  3.   

    data_win.style.top = document.body.scrollTop + window.event.y + "px";
    data_win.style.left = document.body.scrollLeft + window.event.x + "px";
    就可以了。不过你这样弄不兼容FF...
      

  4.   

    a piece of cake! 给你一个例子:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script language="javascript">
    function Point(iX, iY){
    this.x = iX;
    this.y = iY;
    }function fGetXY(aTag){
      var oTmp = aTag;
      var pt = new Point(0,0);
      do {
       pt.x += oTmp.offsetLeft;
       pt.y += oTmp.offsetTop;
       oTmp = oTmp.offsetParent;
      } while(oTmp.tagName!="BODY");
      pt.x+=parseInt(document.body.leftMargin);
      pt.y+=parseInt(document.body.topMargin);
      return pt;
    }function showDiv(div,pos){
    var pt=fGetXY(pos);
    div.style.left=pt.x+pos.offsetWidth;
    div.style.top=pt.y+pos.offsetHeight;
    div.style.display='block';
    }function hideDiv(div){
    div.style.display='none';
    alert()
    }
    </script><style type="text/css">
    <!--
    #Layer1 {
    position:absolute;
    width:150px;
    height:50px;
    z-index:1;
    background-color: #FFFFCC;
    display:none;
    }.key{
    cursor:hand;
    color:blue;
    font-size:12px;
    }
    -->
    </style>
    </head><body>
    <div id="Layer1">啦啦啦,出现了。</div>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span onclick="showDiv(Layer1,this)" class="key">测试链接</span></p>
    <p><span class="key">测试链接</span></p>
    </body></html>
      

  5.   

    谢谢 muxrwc(王辰),
    要兼容ff怎么弄呢?
    sina的新闻页面 他的js我看不明白
    http://news.sina.com.cn/w/2006-12-08/001311729059.shtml
      

  6.   

    <html>
    <head>
    <script type="text/javascript">
    function onmouseMove() {
    function createDIV(id) {
    //创建并且返回DIV
    var div = document.createElement("div")
    div.setAttribute("id", "temp_DIV_" + id);
    document.body.appendChild(div);
    return document.getElementById("temp_DIV_" + id);
    }

    function change(e) {
    //Load数据并且生成DIV设置参数
    var e = window.event || e; //我就会这么一种兼容获取EVENT的方法,好象还有一种可以查找,但是那个好麻烦所以没记..
    var loadValue = "WC" //AJAX加载数据,比如加载完后得到了WC - -#
    this.div = createDIV(this.id);
    with (this.div.style) {
    position = "absolute";
    display = "block";
    left = document.body.scrollLeft + this.offsetLeft + "px";
    top = document.body.scrollTop + (this.offsetTop + this.offsetHeight - 5) + "px";
    }
    this.div.innerHTML = loadValue;
    this.onmousemove = showDIV;
    this.onmouseout = nshowDIV;
    }
    function showDIV() {
    //显示
    this.div.style.display = "block";
    }
    function nshowDIV() {
    //隐藏
    this.div.style.display = "none";
    }
    this.add = function (o) {
    //添加
    o.onmouseover = change;
    }
    }
    window.onload = function () {
    var mo = new onmouseMove;
    mo.add(document.getElementById("wc1"))
    mo.add(document.getElementById("wc2"))
    mo = null;
    }
    </script>
    </head>
    <body>
    <a id="wc1">KEY</a>
    <a id="wc2">KEY</a>
    </body>
    </html>