How to move the JQuery mouse over a small image to display the big image?

Source: Internet
Author: User

How to move the JQuery mouse over a small image to display the big image?

This document describes how to show the effect of a large image by moving the JQuery mouse over a small image. Share it with you for your reference. The specific analysis is as follows:

The function of displaying a large image here is similar to the previous "JQuery method for implementing the effect of Hyperlink mouse prompts". You can modify the code slightly to make a prompt effect for an image.

Refer to the code that prompts the effect of the previous hyperlink. You only need to change the code of the created div element:

// When you create a div element image, the following error occurs: var tooltip = "<div id =" tooltip ">  <\/div> "; </div>

When you move the mouse over the image, a large image is displayed. In order to make the effect more user-friendly, you also need to add the description text for the image, that is, the corresponding description text of the image appears under the large image prompted.

You can obtain the corresponding description text of the Image Based on the title attribute value of the hyperlink. The JQuery code is as follows:

this.myTitle = this.title; this.title = "";  var imgTitle = this.myTitle? "<br />" + this.myTitle : "";

Then append it to the div element. The Code is as follows:

// Create the div element var tooltip = "<div id = 'tooltip '>  ";

The Trielement operation is used to determine whether this. myTitle is. The three-element operation structure is: Boolean? Value 1: Value 2. It must have a Boolean value for the 1st parameters. Of course, the ternary operation can also be replaced by "if () {} else {}", for example:

var imgTitle; if (this.myTitle) {   imgTitle = "<br />" + this.myTitle; } else {   imgTitle = ""; }

In this way, the image prompt effect is complete. When the mouse slides over the image, the picture will be previewed in a large image, and the text below the big picture will be introduced.

The complete code for this example is as follows:

<Script type = "text/javascript"> // <! [CDATA [$ (function () {var x = 10; var y = 20; $ (". tooltip "). mouseover (function (e) {this. myTitle = this. title; this. title = ""; var imgTitle = this. myTitle? "<Br/>" + this. myTitle: ""; var tooltip = "<div id = 'tooltip '>  </script>

I hope this article will help you with jQuery programming.

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.