Lightweight JSToolTip tip effect _ javascript skills

Source: Internet
Author: User
JSToolTip prompts the effect. For more information, see. The mouse prompts appear, more beautiful than the title, can be customized.
JS:

The Code is as follows:


// --------------------------- Tooltip effect start -----------------------------------
// Obtain the location of an html Element
Function GetPos (obj ){
Var pos = new Object ();
Pos. x = obj. offsetLeft;
Pos. y = obj. offsetTop;
While (obj = obj. offsetParent ){
Pos. x + = obj. offsetLeft;
Pos. y + = obj. offsetTop;
}
Return pos;
};

// Prompt Tool
Var ToolTip = {
_ TipPanel: null,
Init: function (){
If (null = this. _ tipPanel ){
Var tempDiv = document. createElement ("p ");
Document. body. insertBefore (tempDiv, document. body. childNodes [0]);
TempDiv. id = "tipPanel ";
TempDiv. style. display = "none ";
TempDiv. style. position = "absolute ";
TempDiv. style. zIndex = "999 ";
}
},
AttachTip: function () {}, // Add a prompt for binding
DetachTip: function () {}, // The removal prompt is bound.
ShowTip: function (oTarget ){
If ($ ("tipPanel") = null)
Return;

/* Procedure
* 1. construct a new html clip.
* 2. Set a new location in the prompt box.
* 3. A prompt box is displayed.
*/
// 1.
Var tempStr = ""; // html clip
If (arguments. length> 1 ){
For (var I = 1; itempStr + ="

"+ Arguments [I] +"

";
}
}
$ ("TipPanel"). innerHTML = tempStr;
// 2.
Var pos = GetPos (oTarget );
$ ("TipPanel"). style. left = (oTarget. offsetWidth/2 + pos. x) + "px ";
$ ("TipPanel"). style. top = (oTarget. offsetHeight + pos. y) + "px ";
// 3.
$ ("TipPanel"). style. display = "";
},
HideTip: function (){
If ($ ("tipPanel") = null)
Return;
$ ("TipPanel"). style. display = "none ";
}
};

// --------------------------- Tooltip effect end -----------------------------------


CSS:

The Code is as follows:


# TipPanel {background: white; padding: 6px 8px; width: 300px; border: solid 4px # 09c; font-size: 14px; color: #555 ;}
# TipPanel p {margin: 0px ;}
# TipPanel B {color: red; font-size: 14px ;}



HTML call:

The Code is as follows:





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.