Create a custom a tag with simple jquery + CSS. The title prompt tooltip_HTML/Xhtml _ webpage creation is displayed.

Source: Internet
Author: User
This article mainly introduces how to create a custom a tag title prompt tooltip with simple jquery + CSS. If you need a tooltip, refer to the introduction below.

Create a custom a tag title prompt with simple jquery + CSS to replace the default browser behavior.



Javascript code

The Code is as follows:


$ (Function (){
$ ("A [title]"). each (function (){
Var a = $ (this );
Var title = a. attr ('title ');
If (title = undefined | title = "") return;
A. data ('title', title)
. RemoveAttr ('title ')
. Hover (
Function (){
Var offset = a. offset ();
$ ("

"). AppendTo ($ ("body" registry.html(title).css ({top: offset. top +. outerHeight () + 10, left: offset. left +. outerWidth () + 1 }). fadeIn (function (){
Var pop = $ (this );
SetTimeout (function () {pop. remove () ;}, pop. text (). length * 80 );
});
},
Function () {$ ("# anchortitlecontainer"). remove ();}
);
});
});


Don't forget to reference JQuery.

SetTimeout (function () {pop. remove () ;}, pop. text (). length * 80) is calculated based on the length of the title, used to prevent too short title prompt too long or too long title prompt too short.

CSS code

The Code is as follows:


# Anchortitlecontainer {
Position: absolute;
Z-index: 5999;
Border: solid 1px # 315B6C;
Padding: 5px;
Color: # 315B6C;
Background: none repeat scroll 0 0 # FFFFFF;
Border-radius: 5px;
Display: none;
}
# Anchortitlecontainer: before {
Position: absolute;
Bottom: auto;
Left:-1px;
Top:-15px;
Border-color: transparent # 315B6C;
Border-style: solid;
Border-width: 15px;
Content :"";
Display: block;
Width: 0;
}
# Anchortitlecontainer: after {
Position: absolute;
Bottom: auto;
Left: 0px;
Top:-13px;
Border-color: transparent # FFFFFF;
Border-style: solid;
Border-width: 15px;
Content :"";
Display: block;
Width: 0;
}


Use some CSS3 features to avoid using images.

I am not a CSS guru. It takes some time to bring up this style. If someone can use it, it would be my pleasure. :)

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.