js tips提示框程式碼

來源:互聯網
上載者:User

這是一款指向文本就會顯示文本小提示哦,就叫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;
 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 showLayerAtBottom(){
 var tip = arguments[0] || null;
 var obj = arguments[1] || null;
 var offsetLeft = arguments[2] || 0;
 var offsetTop  = arguments[3] || 0;
 tip = (typeof tip == 'object') ? tip : document.getElementById(tip) || null;
 if (!tip) return;
 obj = (typeof obj == 'object') ? obj : document.getElementById(obj) || null;
 tip.style.display = 'block';
 var left = getX(obj) + offsetLeft;
 var top  = getY(obj) + obj.offsetHeight + offsetTop;
 if (!document.all) {  //NS
   tip.style.left = left + 'px';
      tip.style.top  = top  + 'px';
    } else {    //IE
      tip.style.pixelLeft = left;
      tip.style.pixelTop  = top;
    }
}
//var tipString = '<strong>訪問<font color=#FF6800><SITE></font>後,請<font color=#ff6800>返回本頁申請</font>,<BR>無需再註冊、發布簡曆。</strong>';
var tipString = '<strong><span style="color:#FF6800;font-size:18px;">請返回本頁申請</span><BR>在本站發布簡曆、毋須到其它網站再註冊。</strong>';

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.