How Jquery implements image magnifiers and its code (self-writing) _ jquery

Source: Internet
Author: User
There are a lot of online magnifiers, so I wrote one myself because it is difficult to implement it. Below I will share with you the specific algorithms and implementation code, if you are interested, you can refer to a large number of restrictions on the Internet, which is hard to understand and troublesome ~ Write one by yourself. Laugh

Algorithm:

Step 1:

Position of the enlarged image = the width or height of the container where the mouse is located divided by the height and width of the container itself to find the percentage of the mouse moving in the container

Part 2:

After the percentage is obtained

X =-(x % * Image Width-display container width/2 );

Y =-(y % * Image Height-display container height/2 );

Two parameters, x and y, are the positions of the big image, followed by a display container size/2 to ensure that the image is displayed in the middle.

:

Code:

The Code is as follows:





Product Information


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.