Home > Web Front-end > JS Tutorial > body text

奇妙的Javascript图片放大镜_图象特效

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

在Flash中我们用蒙板加上一些简单的脚本便可实现一个动态的图片放大镜。现在我们只用JavaScript结合CSS语言也可以轻易做出这个效果。

  制作思路:“放大镜”后有一幅背景图,它是“放大了”的图的原本。我们通过移动“放大镜”时适当调整背景图的位置,使它显示的刚好是需要要放大的部分。

  效果演示: (点这里在新窗口中查看)

  制作步骤

  1)先准备两幅内容相同尺寸不同的图片,这里我们找了一个400×300像素的缩略图small_hill.gif,一个800×600像素的大图big_hill.gif。然后再准备一个“放大镜”的图片,注意它中间部分必须是透明的,这里我们准备了一个绿色的方框 viewer.gif。

  2)编写如下的代码:

  以下是两幅图的代码,都它们作为层。第一幅是缩略图,第二幅是“放大镜”,首先将它的背景移到不可见的地方; 其中“ onclick="moveme=!moveme" ”表示每次点击它都改变“moveme”的布尔值。

奇妙的Javascript图片放大镜_图象特效"small_hill.gif" id="bgLayer" style="position:absolute; left:150px; top:50px;">
奇妙的Javascript图片放大镜_图象特效"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;">

以下是JavaScript脚本:


 

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!