Creating Custom ToolTips

The TreeView behavior provides a default ToolTip that displays when a user hovers over a TREENODE element. You may want your users to have more specific information than is provided by the default ToolTip (Use +/- to expand/collapse) accessed by the SHOWTOOLTIP attribute. You can accomplish this by creating three simple DHTML functions that use the ONHOVER and ONUNHOVER events to replace the default ToolTip.

The following sample shows what these methods might look like. The sample uses the TEXT attribute of the TreeNode object as the ToolTip text, but you could customize this to provide any information that you choose.
// ToolTip functions include starthover(), starttip(), and endtip()
 
    // ToolTip variables
    var myTimer;
    var nodeText;
    var tipX;
    var tipY;

function starthover()
{
    var myVal = window.event.treeNodeIndex;
    var myNode = oTree.getTreeNode(myVal);

    nodeText = myNode.getAttribute("text");
    tipX = window.event.clientX + 15;
    tipY = window.event.clientY + 15;

    myTimer = window.setTimeout(starttip, 1000);
}

function starttip()
{
    results1.style.backgroundColor = "infobackground";
    results1.style.position = "absolute";
    results1.style.left = tipX;
    results1.style.top = tipY;
    results1.style.border = "1px solid black";
    results1.innerText = nodeText;

    myTimer = window.setTimeout(endtip, 5000);
}

function endtip()
{
    results1.style.backgroundColor = "";
    results1.innerText = "";
    results1.style.border = "";
    window.clearTimeout(myTimer);
}
</HEAD>
    <BODY>
    <mytree:TREEVIEW id="oTree" TREENODESRC="state_city.xml"
    SHOWTOOLTIP="false" ONHOVER="starthover();" ONUNHOVER="endtip();" />
<!--This DIV is required to display the ToolTips-->
    <DIV id=results1></DIV>
    </BODY>
</HTML>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值