Jquery enables the mouse to move up and a prompt box pops up, removing and disappearing

Source: Internet
Author: User

Ideas:

1. First, you need to locate the elements that implement this effect.

2. If different prompts are dynamically displayed, you need to set the title

3. Add the mouseover and mouseout events to the located element through JQ.

4. Complete the settings and move the mouse on the target element.

5. Merge mouseover and mouseout into hover.

 

 

[Javascript] // page Load completed
$ (Function (){
Var x = 10;
Var y = 20; // sets the offset position of the prompt box to prevent the mouse from being blocked.
$ (". Prompt"). hover (function (e) {// move the cursor over event
This. myTitle = this. title; // assign the title to the custom attribute myTilte, shielding the built-in prompt
This. title = "";
Var tooltipHtml = "<div id = 'tooltip '>" + this. myTitle + "</div>"; // create a prompt box
$ ("Body"). append (tooltipHtml); // Add to page
$ ("# Tooltip" ).css ({
"Top": (e. pageY + y) + "px ",
"Left": (e. pageX + x) + "px"
}). Show ("fast"); // sets the coordinates of the prompt box and displays
}, Function () {// mouse removal event
This. title = this. myTitle; // reset the title.
$ ("# Tooltip"). remove (); // The remove dialog box appears.
}). Mousemove (function (e) {// move the event following the mouse
$ ("# Toolti" ).css ({"top": (e. pageY + y) + "px ",
"Left": (e. pageX + x) + "px"
});
});
});

// Page loaded
$ (Function (){
Var x = 10;
Var y = 20; // sets the offset position of the prompt box to prevent the mouse from being blocked.
$ (". Prompt"). hover (function (e) {// move the cursor over event
This. myTitle = this. title; // assign the title to the custom attribute myTilte, shielding the built-in prompt
This. title = "";
Var tooltipHtml = "<div id = 'tooltip '>" + this. myTitle + "</div>"; // create a prompt box
$ ("Body"). append (tooltipHtml); // Add to page
$ ("# Tooltip" ).css ({
"Top": (e. pageY + y) + "px ",
"Left": (e. pageX + x) + "px"
}). Show ("fast"); // sets the coordinates of the prompt box and displays
}, Function () {// mouse removal event
This. title = this. myTitle; // reset the title.
$ ("# Tooltip"). remove (); // The remove dialog box appears.
}). Mousemove (function (e) {// move the event following the mouse
$ ("# Toolti" ).css ({"top": (e. pageY + y) + "px ",
"Left": (e. pageX + x) + "px"
});
});
});

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.