這是一款指向文本就會顯示文本小提示哦,就叫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>';