Jquery-based custom mouse tip effects jquery. toolTip

Source: Internet
Author: User

IE Effect

Firefox or other browsers


Code

Copy codeThe Code is as follows: // copyright: www.kuchechina.com, China
// Author: zhuyue.cnblogs.com
// Demonstration http://www.kuchechina.com/carstools/Default.aspx
JQuery. fn. toolTip = function (){
This. unbind (). hover (
Function (e ){
This. t = this. title;
This. title = '';
$ ('Body '). append ('<p id = "p_toolTip" style = "display: none; max-width: 320px; text-align: left; "> '+ this. t + '</p> ');
Var tip = require ('p;p_tooltip'}.css ({"position": "absolute", "padding": "10px 5px 5px 10px", "left": "5px", "font-size ": "14px", "background-color": "white", "border": "1px solid # a6c9e2", "line-height": "160% ", "-moz-border-radius": "5px", "-webkit-border-radius": "5px", "z-index": "9999 "});
Var target = $ (this );
Var position = target. position ();
This. top = (position. top-8); this. left = (position. left + target. width () + 5 );
$ ('P # p_toolTip extends img_tooltip_arrow'}.css ({"position": "absolute", "top": "8px", "left": "-6px "});
Tip.css ({"top": this. top + "px", "left": this. left + "px "});
Tip. fadeIn ("slow ");
},
Function (){
This. title = this. t;
$ ("P # p_toolTip"). fadeOut ("slow"). remove ();
}
);
};

Usage:Copy codeThe Code is as follows: <script type = "text/javascript">
$ (Document). ready (function (){
$ ("# TootlsMain img [title]"). toolTip ();
});
</Script>

You can use the jquery selector to select a tag with the title attribute. Of course, you can modify the code to apply the tag with the alt attribute.
The title attribute supports simple html tags. For example, <br/>. Note the use of quotation marks
Implementation principle:
Use the label title attribute to replace the default mouse event with the hover event to display the floating layer. This. unbind (). hover is the code. Jquery helps us do a lot of things. Just pile up our real code.
Programmer, I hope you can understand it.

Code download

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.