Chinaunix首页 | 论坛 | 博客
  • 博客访问: 465036
  • 博文数量: 226
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2111
  • 用 户 组: 普通用户
  • 注册时间: 2014-06-20 09:02
个人简介

web web web

文章分类

全部博文(226)

文章存档

2020年(2)

2019年(1)

2018年(3)

2017年(26)

2016年(57)

2015年(60)

2014年(77)

我的朋友

分类: Web开发

2014-09-17 16:18:22

      对于一些比较小的图片,通过鼠标移动到图片上进行放大显示,原理很简单,就是将图片显示的尺寸变大后放在浏览器的一个指定位置,从而实现图片的放大预览。以下是代码:

点击(此处)折叠或打开

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

  2. <html xmlns="">
  3. <head>
  4. <title>jQuery图片预览</title>
  5. <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
  6. <style type="text/css">
  7. body{font-size:12px; padding:50px;}
  8. .clsImg{padding-top:300px;}
  9. .imgAttr{position:absolute; height:225px; width:300px; border:1px solid #ccc; margin-left:135px; display:none;}
  10. </style>
  11. <script type="text/javascript">
  12. $(function () {
  13. var x = 0;
  14. var y = 0;
  15. $("img").mouseover(function (e) { //鼠标移动到图片上添加事件,显示放大图片
  16.     $("#imgShow").attr("src", this.src).show();
  17. });
  18. $("img").mouseout(function () { //鼠标从图片移开图片隐藏
  19.     $("#imgShow").hide();
  20. });
  21. })

  22. </script>
  23. </head>
  24. <body>
  25. <img class="imgAttr" id="imgShow" src="" alt=""/>
  26. <img class="clsImg" src="img1.jpg" alt=""/>
  27. <img class="clsImg" src="img2.jpg" alt=""/>
  28. <img class="clsImg" src="img3.jpg" alt=""/>
  29. <img class="clsImg" src="img4.jpg" alt=""/>

  30. </body>
  31. </html>

阅读(587) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~