Javascript _ uses CSS inline style to simulate the tooltip;

Source: Internet
Author: User

=> Implementation function: JS event-driven and CSS inline style simulation tooltip;

<HTML>

<Head>
<Title> tips for using CSS </title>
<SCRIPT type = "text/JavaScript">
Function tooltip (){
This. tooltip = Document. createelement ("Div ");
This. tooltip. style. Position = "absolute ";
This. tooltip. style. width = "250px ";
This. tooltip. style. Height = "150px ";
This. tooltip. style. backgroundcolor = "lightgray ";
This. tooltip. style. Border = "3px outset black ";
This. tooltip. style. Visibility = "visible ";
This. tooltip. ID = "tooltip ";
This. tooltip. classname = "tooltipshadow ";

This. content = Document. createelement ("Div ");
This. content. style. Position = "relative ";
This. content. ID = "tipcontent ";
This. content. classname = "tooltipcontent ";

This. tooltip. appendchild (this. content );

Console. Log ("tooltip class ");
}
Tooltip. Prototype. Show = function (text, x, y ){
This. content. innerhtml = text;
This. tooltip. style. Left = x + "PX ";
This. tooltip. style. Top = Y + "PX ";
This. tooltip. style. Visibility = "visible ";

If (this. tooltip. parentnode! = Document. Body ){
Document. Body. appendchild (this. tooltip );
}

Console. Log ("tooltip show method ");
}
Tooltip. Prototype. Hide = function (){
This. tooltip. style. Visibility = "hidden ";

Console. Log ("tooltip hide method ");
}

Function firefn (){
// Obtain the selected text
VaR text = "";
If (window. getselection ){
TEXT = Window. getselection (). tostring ();
} Else if (document. getselection ){
TEXT = Document. getselection ();
} Else if (document. Selection ){
TEXT = Document. selection. createRange (). text;
}

VaR tip = new tooltip ();
Tip. Show (text, 100,100 );
SetTimeout (function (){
Tip. Hide ();
},2000 );
}
</SCRIPT>
</Head>
<Body>
<P onmouseup = "firefn ()"> many colleagues who are about to develop software or who have not been doing it for a long time mostly focus on new technologies and creativity; but there is always a shadow in the sun,
No matter how the method changes, there is always something that cannot be completely improved. </P>
</Body>
</Html>

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.