图片放大镜效果

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta charset="utf-8"/>
 5     <title>图片放大镜效果</title>
 6     <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css" media="all"/>
 7     <link rel="stylesheet" type="text/css" href="../css/bootstrap-theme.min.css" media="all"/>
 8     <link rel="stylesheet" type="text/css" href="../css/reset.css" media="all"/>
 9     <style type="text/css">
10         .demo{ width:350px;margin:30px auto; text-align:left; padding:0; }
11         #div{border:1px solid #ccc; position:relative; }
12         #div .small_pic{ width:350px; height:350px; background:#eee; position:relative; }
13         #div .float_layer{ width:100px; height:100px; border:1px solid #000; background:#fff; filter:alpha(opacity:30); opacity:0.3; position:absolute; top:0; left:0; display:none; }
14         #div .mark{ width:100%; height:100%; position:absolute; z-index:2; left:0px; top:0px; background:red; filter:alpha(opacity:0); opacity:0; }
15         #div .big_pic{ position:absolute; top:-1px; left:360px; width:250px; height:250px; overflow:hidden; border:2px solid #CCC; display:none; }
16         #div .big_pic img{ position:absolute; top:-30px; left:-80px; }
17     </style>
18 </head>
19 <body>
20 <div id="div" class="demo">
21     <div class="small_pic">
22         <span class="mark"></span>
23         <span class="float_layer"></span>
24         <img src="images/small.jpg" alt="放大镜图片一"/>
25     </div>
26
27     <div class="big_pic">
28         <img src="images/big.jpg" alt="放大镜图片二"/>
29     </div>
30 </div>
31 <script>
32     (function(){
33         var div = document.getElementById(‘div‘);
34         var small = getByCls(div, ‘small_pic‘)[0];
35         var big = getByCls(div, ‘big_pic‘)[0];
36         var img = big.getElementsByTagName(‘img‘)[0];
37         var mark = small.getElementsByTagName(‘span‘)[0];
38         var layer = small.getElementsByTagName(‘span‘)[1];
39         small.onmousemove = function(e){
40             e = e || event;
41             this.style.cursor = ‘move‘;
42             layer.style.display = big.style.display = ‘block‘;
43             var t = e.clientY - div.offsetTop - layer.clientHeight/2;
44             var l = e.clientX - div.offsetLeft - layer.clientWidth/2;
45             if(t < 0){
46                 t = 0;
47             } else if(t > div.clientHeight - layer.clientHeight){
48                 t = div.clientHeight - layer.clientHeight;
49             }
50             if(l < 0){
51                 l = 0;
52             } else if(l > div.clientWidth - layer.clientWidth){
53                 l = div.clientWidth - layer.clientWidth;
54             }
55             var scaleX = l / (div.clientHeight - layer.clientHeight);
56             var scaleY = t / (div.clientWidth - layer.clientWidth);
57             layer.style.top = t + ‘px‘;
58             layer.style.left = l + ‘px‘;
59             img.style.left = -scaleX * (img.clientWidth - big.clientWidth) + ‘px‘;
60             img.style.top = -scaleY * (img.clientHeight - big.clientHeight) + ‘px‘;
61         }
62         small.onmouseout = function(e){
63             layer.style.display = big.style.display = ‘none‘;
64         }
65         function getByCls(obj, cls){
66             if(obj.getElementsByClassName){
67                 return obj.getElementsByClassName(cls);
68             } else {
69                 var res = [],
70                     reg = new RegExp(‘^|\\s+‘ + cls + ‘\\s+|$‘),
71                     all = obj.all;
72                 for(var i = 0; i < all.length; i++){
73                     if(reg.test(all[i].className)){
74                         res.push(all[i]);
75                     }
76                 }
77                 return res;
78             }
79         }
80     }());
81 </script>
82 </body>
83 </html>

时间: 2024-10-13 22:46:31

图片放大镜效果的相关文章

利用jqueryzoom实现图片放大镜效果

在你的页面中包含 jqzoom.css Html代码   <link rel="stylesheet" href="your_path/jqzoom.css" type="text/css" media="screen"> 包含 jQzoom 和 jQuery JS 代码: Html代码   <script type="text/javascript" src="your_pat

jquery图片放大镜效果制作变焦镜头图片放大查看

jquery图片放大镜效果制作变焦镜头图片放大查看 http://www.17sucai.com/pins/demoshow/8511

WPF设置VistualBrush的Visual属性制作图片放大镜效果

原文:WPF设置VistualBrush的Visual属性制作图片放大镜效果 效果图片: 原理:设置VistualBrush的Visual属性,利用它的Viewbox属性进行缩放. XAML代码:// Window1.xaml<Window x:Class="MagnifyingGlass.Window1"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns

canvas知识02:图片放大镜效果

效果截图: JS代码: <script> // 初始化canvas01和上下文环境 var cav01 = document.getElementById('cav01'); var cxt01 = cav01.getContext('2d'); // 初始化canvas02和上下文环境 var cav02 = document.getElementById('cav02'); var cxt02 = cav02.getContext('2d'); //初始化image对象和缩放比例 var

jQuery和CSS3打造逼真的图片放大镜效果

这是一款效果非常逼真的jQuery和CSS3超逼真的图片放大镜特效.该图片放大镜特效使用CSS3的box-shadow和border-radius实现来制作放大镜的样式,使用jQuery来获取当前鼠标的坐标系,并修改当前坐标系的背景图像. 在线演示: 下载地址:http://www.htmleaf.com/jQuery/Image-Effects/201503171533.html

[前端练习小Demo]图片放大镜效果

最终效果展示: JS部分: window.onload=function(){ var normal = document.getElementById('normal'); var lay = document.getElementById("lay"); var bigImg = document.getElementById("bigImg"); var img = bigImg.getElementsByTagName('img')[0]; normal.o

js京东图片放大镜效果。

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>放大镜</title> <style> *{ margin: 0; padding: 0; } /* 去除图片的3px */ img { vertical-align: top; } /* 容器样式 */ .container { width:

商品图片放大镜效果

效果如下 使用步骤(非常简单): 1.引入css <link rel="stylesheet" href="magiczoom/MagicZoom.css"/> 2.引入js  <script src="magiczoom.js" type="text/javascript"></script> 3.应用到标签中 <body> <a href="201042112

js的小效果-图片放大镜效果

<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style> *{margin: 0;padding:0;} #small{ width:350px; height:350px; border:1px solid #000; position:relative; float: