当前鼠标位置的工具提示 [英] Tooltip with current mouse location

查看:89
本文介绍了当前鼠标位置的工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法正确找到工具提示的位置.我希望它能与鼠标一起工作,这是大多数工具提示的工作方式.
如果将鼠标悬停在网格外部的标签上,则提示信息正确.但是,如果我对数据网格中的控件使用相同的代码,则会增加工具提示的位置(特别是Y轴).
这是代码-

I cant get the position right for tooltip. I want it to be with the mouse, the way most of the tooltip work.
If I mouseover a label outside the grid, then the tooltip is coming properly. But if I use the same code for a control inside a datagrid, then tooltip''s location (y-axis specially) increases.
Here is the code -

var cX = 0;
var cY = 0;
var rX = 0;
var rY = 0;

function UpdateCursorPosition(e) { cX = e.pageX; cY = e.pageY; }

function UpdateCursorPositionDocAll(e) { cX = event.clientX; cY = event.clientY; }
if (document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
    if (self.pageYOffset) {
        rX = self.pageXOffset;
        rY = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) {
        rX = document.documentElement.scrollLeft;
        rY = document.documentElement.scrollTop;
    }
    else if (document.body) {
        rX = document.body.scrollLeft;
        rY = document.body.scrollTop;
    }
    if (document.all) {
        cX += rX;
        cY += rY;
    }
    d.style.left = (cX + 10) + "px";
    d.style.top = (cY + 10) + "px";
}

function HideContent(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
    if (d.length < 1) { return; }
    var dd = document.getElementById(d);
    AssignPosition(dd);
    dd.style.display = "block";
}

推荐答案

为什么不使用ASP.Net WebControl工具提示:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.tooltip.aspx [
Why dont you use ASP.Net WebControl tooltip:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.tooltip.aspx[^]


这篇关于当前鼠标位置的工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆