js tips提示框程序代码

时间:2013-02-24 02:10:02  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:w Point(0,0); document.onmousemove = mouseMove; function mouseMove(ev){   ev  = ev || window.event;   var mousePos = mouseCoords(ev);   mLoc.x = mousePos.x;   mLoc.y = mousePos.y; } function mouseCoords(ev){   if(ev.pageX || ev.pageY){ return {x:ev.pageX, y:ev.pageY}; }...
  正文:js(第二电脑网http://www.002pc.com) tiphotoshop/ target=_blank class=infotextkey>ps提示框程序代码

js(第二电脑网http://www.002pc.com) tips提示框程序代码

这是一款指向文本就会显示文本小提示哦,就叫tips提示框

function Point(x,y) { this.x=x; this.y=y; }
var mLoc = new Point(0,0);
document.onmousemove = mouseMove;
function mouseMove(ev){
  ev  = ev || window.event;
  var mousePos = mouseCoords(ev);
  mLoc.x = mousePos.x;
  mLoc.y = mousePos.y;
}
function mouseCoords(ev){
  if(ev.pageX || ev.pageY){ return {x:ev.pageX, y:ev.pageY}; }
  return { x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
     y:ev.clientY + document.body.scrollTop  - document.body.clientTop };
}
function getX(elm) {
 var x=0; while (elm) { x+=elm.offsetLeft; elm=elm.offsetParent; } return x;
}
function getY(elm) {
 var y=0; while (elm) { y+=elm.offsetTop;  elm=elm.offsetParent; } return y;
}
function showTipFollowMouse(div_id, txt){
 if (txt.match(/^s*$/)) return;
 var tip=document.getElementById(div_id) || null;
 if (!tip) return;
 tip.innerHTML = txt;
 tip.style.display = 'block'; 
 var left = mLoc.x + 12;
 var top  = mLoc.y + 12;
 if (left+tip.offsetWidth >= document.body.offsetWidth)
  left = left-tip.scrollWidth-20;
 if (left<0) left=1; 
 if (top+tip.offsetHeight >= document.body.offsetHeight+document.body.scrollTop)
  top = top-tip.offsetHeight-20;
 if (top<0)  top=1; 
 if (!document.all) {  //NS
   tip.style.left =  left + 'px';
   tip.style.top  =  top  + 'px';
    } else {    //IE
      tip.style.pixelLeft = left;
   tip.style.pixelTop  = top;
    } 
}
function hideTip(id){
 var tip=document.getElementById(id) || null;
 if(tip) tip.style.display='none';
}
// arguments: tip, txt, object, offsetLeft, offsetTop
function showTipAtTop(){
 var tip = arguments[0] || null;
 var txt = arguments[1] || '';
 var obj = arguments[2] || null;
 var offsetLeft = arguments[3] || 0;
 var offsetTop  = arguments[4] || 0; 
 tip = (typeof tip == 'object') ? tip : document.getElementById(tip) || null;
 if (!tip) return;
 if (txt.match(/^s*$/)) return;
 obj = (typeof obj == 'object') ? obj : document.getElementById(obj) || null;
 tip.innerHTML = txt;  
 tip.style.display = 'block';
 var left = getX(obj) - offsetLeft;
 var top  = getY(obj) - tip.offsetHeight - offsetTop;
 if (left+tip.offsetWidth >= document.body.offsetWidth)
  left = left-tip.offsetWidth+(obj.offsetWidth || 0);
 if (left<0) left=1;
 if (!document.all) {  //NS
   tip.style.left = left + 'px';
      tip.style.top  = top + 'px';
    } else {    //IE
      tip.style.pixelLeft = left;
      tip.style.pixelTop  = top;
    } 
}
function showTipAtBottom(){
 var tip = arguments[0] || null;
 var txt = arguments[1] || '';
 var obj = arguments[2] || null;
 var offsetLeft = arguments[3] || 0;
 var offsetTop  = arguments[4] || 0;
 tip = (typeof tip == 'object') ? tip : document.getElementById(tip) || null;
 if (!tip) return; "js tips提示框程序代码"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Programming/JavaScript/26203.html


关于《js tips提示框程序代码》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td