JQuery预览图片
2016-04-20 11:08
591 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>jQuery图片预览</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> var ShowImage = function() { xOffset = 10; yOffset = 30; jQuery("#imglist").find("img").hover(function(e) { jQuery("<img id='imgshow' src='" + this.src + "' />").appendTo("body"); jQuery("#imgshow") .css("top", (e.pageY - xOffset) + "px") .css("left", (e.pageX + yOffset) + "px") .fadeIn("fast"); }, function() { jQuery("#imgshow").remove(); }); jQuery("#imglist").find("img").mousemove(function(e) { jQuery("#imgshow") .css("top", (e.pageY - xOffset) + "px") .css("left", (e.pageX + yOffset) + "px") }); }; jQuery(document).ready(function() { ShowImage(); }); </script> <style type="text/css"> body{ width:600px; margin:0 auto;} img{border:none;} ul,li{ margin:0; padding:0; } li{ list-style:none; float:left; display:inline; margin-right:10px; } #imglist img{width:150px;height:120px;} #imgshow{ position:absolute; border:1px solid #ccc; background:#333; padding:5px; color:#fff; display:none; } </style> </head> <body> <ul id="imglist"> <li><a><img src="http://www.jquery001.com/images/demo/35624390.jpg" alt="安以轩" /></a></li> <li><a><img src="http://www.jquery001.com/images/demo/35624390.jpg" alt="安以轩" /></a></li> </ul> </body> </html>
原文地址:http://www.jquery001.com/jquery-image-preview.html
相关文章推荐
- Jquery点击发送按钮后,按钮文本倒计时
- JQuery的silder代码
- JQuery中toggle被淘汰后的替代方法
- JQuery中使用ajax $.ajax()
- DOM文档加载顺序
- Spring MVC中通过Jquery低版本的ajax传递参数值 遇到415的错误
- 深入理解JQuery插件开发
- 十条jQuery代码片段助力Web开发效率提升
- 对于jQuery中事件绑定的一点说明
- jQuery中iframe的操作(点击按钮新增窗口)
- jQuery Ajax 实例 ($.ajax、$.post、$.get)
- Jquery五角星评分效果
- jquery强大的验证控件jquery-validate
- jquery中detach()移除元素
- 使用Jquery实现点击文字变成输入框、点击按钮刷新网页
- JQuery Ajax 详解
- jquery submit()不能提交表单
- jquery同一标签绑定多个事件的几种方式
- 【转载】jQuery Validate 菜鸟教程
- 【转载】jQuery Validate验证框架 + CKEditor 无法验证问题的解决方法