title效果

来源:互联网 发布:俄语拼写检查软件 编辑:程序博客网 时间:2024/04/29 01:38

 
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"));
}

原创粉丝点击