Mouse hover over link appears text description effect

Source: Internet
Author: User

The mouse hovers over the link and the text shows the effect:
For hyperlinks <a> tags, there is a title property, when the mouse table hovers over the link, it will display the title of the property value, although to a certain extent satisfies our needs, but the beauty is not satisfactory, and can not modify its style, Here's how to do this with jquery simulations.
The code is as follows:

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.softwhy.com/" /><title>Ant Tribe</title><Scripttype= "Text/javascript"src= "Mytest/jquery/jquery-1.8.3.js"></Script> <Scripttype= "Text/javascript"> $(function(){   varx= 7; vary= 8; $("A.tip"). Hover (function(){     vartitle= This. title; var$div=$("<div id= ' Newtip ' >"+title+"</div>"); $( This). Append ($div); $( This). css ({"position":"relative"}); $div. css ({"position":"Absolute","background":"Pink"}); $div. css ({"width":"120px","Height":"30px"}); },function(){     $("#newTip"). Remove (); }). MouseMove (function(e) {var$div= $("#newTip"). css ({" Left":(E.pagex+x)+'px',"Top":(E.pagey+y)+'px'}); }); }) </Script> </Head> <Body> <ahref="#"class= "Tip"title= "Ant Tribe welcomes You">Ant Tribe</a> </Body> </HTML>

The above code when the mouse hover over the link, can appear text description and can follow the mouse movement, the following describes its implementation process.
A. Code Comment:
1.$ (function () {)), when the secure structure is fully loaded and then executes the code in the function.
2.var x = 7,var y = 8, declare two variables to define the horizontal and vertical distances of the mouse pointer and the pop-up layer.
3.$ ("A.tip"). Hover (function () {},function () {}), add mouse hover for the specified link and function to execute when the mouse leaves.
4.var Title=this.title, assigns the value of the title property of the current link to the variable title.
5.var $div =$ ("<div id= ' Newtip ' >" +title+ "</div>"), create a JQuery object, in fact, the div is placed in the title attribute value, this is the layer to be ejected.
6.$ (This). Append ($div), adds the created div to the current link <a>.
7.$ (this). css ({"position": "Relative"}), set hyperlink A to relative positioning, because the popup layer is absolutely positioned, then the positioning reference object can be a link.
8. $div. css ({"position": "absolute", "background": "Pink"}), set the div to absolute positioning, and the background color to be pink.
9. $div. css ({"width": "120px", "height": "30px"}), set the size of the div.
10.$ ("#newTip"). Remove (), delete the element with the specified ID, and this is the delete popup div.
11.mousemove (function (e) {}), register the MouseMove event handler, which is, of course, a chained call.
12.var $div = $ ("#newTip"). CSS ({"Left": (e.pagex+x) + ' px ', "Top": (e.pagey+y) + ' px '}), set the left and top property values of the popup div to achieve the following effect.
two. Related reading:
1.hover () refer to the hover event section of jquery .
2.this refer to the chapter in this usage of JavaScript .
the 3.append () function can be found in the Append () method section of jquery .
the 4.css () function can be found in the section of the CSS () method of jquery .
the 5.remove () function is a section of the Remove () method of jquery .
The 6.mousemove event can be found in the MouseMove event section of jquery .
7.e.pagex can refer to the Event.pagex Properties section of jquery .
8. Relative positioning can be found in the relative positioning of CSS section.
9. Absolute positioning can be found in the absolute positioning of CSS section.

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=11405

For more information, refer to: http://www.softwhy.com/jquery/

Mouse hover over link appears text description effect

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.