The following image sample code is displayed in the jQuery mouse link.

Source: Internet
Author: User

The following image sample code is displayed in the jQuery mouse link.

This article introduces a commonly used effect, that is, when the mouse slides over the link, a layer that follows the mouse pointer can appear. in actual application, generally, it refers to some explanatory text or images of links. The following is a code example:

<! DOCTYPE html> 

:

The above code implements our requirements. The following describes the implementation process:
Code comment:
1. this. screenshotPreview = function (){},Declare a function to achieve the following effect. In this effect, this can be omitted, and it points to window.
2. xOffset = 10,Declare a variable to specify the horizontal distance between the mouse pointer and the displayed image.
3. yOffset = 30,Declare a variable to specify the vertical distance between the mouse pointer and the displayed image.
4. $ ("a. screenshot"). hover (function (e) {}, function (e ){}),Specifies the function to be executed when the mouse moves to the link and leaves the link.
5. this. t = this. title,Assign the title attribute value of the link to the t attribute. here this is the link object that points to the current mouse.
6. var c = (this. t! = "")? "<Br/>" + this. t :"",If this. t is not empty, that is, the title attribute value exists, insert a linefeed and connect the content of the current title. Otherwise, set c to null.
7. $ ("body "). append ("<p id = 'screenshot '> "),Add the image and related instructions to the body.
8. $ ("# screenshot" example .css ("top", (e. pageY-xOffset) + "px" ).css ("left", (e. pageX + yOffset) + "px "). fadeIn ("fast "),Set the top and left attribute values of the p element and use the fade-in effect.
9. this. title = this. t,Assign the title content to this. title. In fact, there is no problem with this sentence. It is a bit redundant.
10. $ ("# screenshot"). remove (),Remove the p element.
11. $ ("a. screenshot"). mousemove (function (e ){}),It is used to set the image to follow when the mouse pointer moves.
12. $ ("# screenshot" example .css ("top", (e. pageY-xOffset) + "px "). css ("left", (e. pageX + yOffset) + "px "),Set the top and left attribute values of the p element to achieve the following effect.

The above is all the content of this article, hoping to help you learn.

Articles you may be interested in:
  • JQuery Implementation of Hyperlink mouse tip effect method
  • JQuery implements the method of hiding layer text links when the mouse passes
  • JQuery allows you to move the mouse over a link to control the slide, expand, and hide of an image.

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.