如何定制页面提示信息

    文章来源:万象互联 更新时间:2012-6-14 16:14:10
分享:

一个页面上往往有很多链接、按钮,如果没有任何提示信息,会让人很迷茫。虽然IE也带提示功能,只要给title属性赋值,如下代码 <a href="#" title="this a test">自带的提示</a>这样的提示很单调,鼠标移上去的时候显示出来,当鼠标在上面移动的时候,提示信息不会跟随,对比下面自定义的提示信息,差别就很明显,所以自定义的提示信息是很有必要的。

把鼠标放到链接上看提示信息如何定制提示信息,说起来很简单,先画出提示信息层,然后定位到目标对象。下面把实现分三部来说明:

1)绘制信息层

有两种方式,一种是静态,把层的html代码写在文档中,另外一种是动态,运用javascript脚本动态的创建层。静态方式简单,不灵活,动态的灵活,但比较困难,需要熟悉脚本和Dom结构,下面的代码是动态方式创建提示层

function createDivTooltip()

{

var divTips = document.createElement('div');//create div element

divTips.id='tooltip';

divTips.style.display='none'//invisible

document.body.appendChild(divTips);

}

2)定位信息层

function locate(e)

{ e=e||window.event;

var divTips = document.getElementById('tooltip');

var mousePos=getMousePosition(e);//get the coordinate of the mouse

divTips.style.top=mousePos.top-12+"px";

divTips.style.left=mousePos.left-8+"px";

}

版权说明:本站原创文章,由万象互联SEO优化发表.
本文地址:https://www.hulian.top/zixun/post/4991.html
在线咨询
  • 在线时间
  • 8:00-21:00