Home > Web Front-end > JS Tutorial > Wonderful Javascript picture magnifying glass_image special effects

Wonderful Javascript picture magnifying glass_image special effects

WBOY
Release: 2016-05-16 19:27:49
Original
1530 people have browsed it

In Flash, we can use a mask and some simple scripts to create a dynamic picture magnifying glass. Now we can easily achieve this effect using only JavaScript combined with CSS language.

 Production idea: There is a background image behind the "magnifying glass", which is the original of the "enlarged" image. We adjust the position of the background image appropriately when moving the "magnifying glass" so that it displays exactly the part that needs to be enlarged.

 Effect demonstration: (Click here to view in a new window)

 Production steps:

1) First prepare two pictures with the same content and different sizes. Here we find a 400×300 pixel thumbnail small_hill.gif and a 800×600 pixel large picture big_hill.gif. Then prepare a "magnifying glass" picture. Note that the middle part must be transparent. Here we have prepared a green box viewer.gif.

2) Write the following code:

The following is the code for the two pictures, both of which are used as layers. The first one is a thumbnail, and the second one is a "magnifying glass", which first moves its background to an invisible place; where "onclick="moveme=!moveme"" means that every time it is clicked, the boolean of "moveme" is changed. value.

"small_hill.gif" id="bgLayer" style= "position:absolute; left:150px; top:50px;">
"viewer.gif" id="myviewer" onclick="moveme=!moveme" onmousemove="viewit (this)"
style=
"left:0;top:0;background-repeat:no-repeat; background-position:2000px 2000px;position:absolute;" >

The following is the JavaScript script:


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template