title效果

 
var CommentViewer=new Object();
CommentViewer.commentDiv=document.createElement("div");
CommentViewer.commentDiv.style.backgroundColor="orange";
CommentViewer.commentDiv.style.zIndex=99;
CommentViewer.commentDiv.style.position="absolute";
CommentViewer.commentDiv.style.display="none";
CommentViewer.divShowed=false;//该div是否显示过了
CommentViewer.delay=1000;//延迟的毫秒数
CommentViewer.timer=null;
CommentViewer.element=null;
CommentViewer.registerViewSource=function(elem){
 elem.attachEvent("onmouseover",this.handleMouseOver);
 elem.attachEvent("onmouseout",this.handleMouseOut);
}
CommentViewer.handleMouseOver=function(){
 if(!event.srcElement){
  return;
 }
 CommentViewer.element=event.srcElement;
 CommentViewer.timer=setTimeout(CommentViewer.showComment,CommentViewer.delay);
}
CommentViewer.handleMouseOut=function(){
 clearTimeout(CommentViewer.timer);
 CommentViewer.commentDiv.style.display="none";
}
CommentViewer.showComment=function(){
 var elem=CommentViewer.element;
 var nodeName=elem.nodeName;
 var text=null;
 if(nodeName&&(nodeName=="INPUT"||nodeName=="SELECT")){//如果是表单域
  text=elem.value;
 }else{//否则为页面元素
  text=elem.innerText;
 }
 var coord=CommentViewer.getAbsolutePosition(elem,document);
 CommentViewer.commentDiv.style.left=coord.x;
 CommentViewer.commentDiv.style.top=coord.y+25;
 if(CommentViewer.divShowed==false){
  document.body.insertAdjacentElement("afterBegin",CommentViewer.commentDiv);
  CommentViewer.divShowed=true;
 }
 CommentViewer.commentDiv.innerText=text;
 CommentViewer.commentDiv.style.display="";
}
CommentViewer.getAbsolutePosition=function(obj, offsetObj){
 var _offsetObj=(offsetObj)?offsetObj:document.body;
 var x=obj.offsetLeft;
 var y=obj.offsetTop;
 var pos=new Object();
 var tmpObj=obj.offsetParent;
 while ((tmpObj!=_offsetObj) && tmpObj){
  x+=tmpObj.offsetLeft+tmpObj.clientLeft-tmpObj.scrollLeft;
  y+=tmpObj.offsetTop+tmpObj.clientTop-tmpObj.scrollTop;
  tmpObj=tmpObj.offsetParent;
 }
 pos.x=x;
 pos.y=y;
 return pos;
}

 

window.attachEvent("onload",init);
function init(){
 CommentViewer.registerViewSource($("menu1"));
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值