简单的图片放大镜效果插件

记录下

html代码

<!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" />
<meta content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=1;" name="viewport" />
<link rel="stylesheet" href="http://s2.hqbcdn.com/mobile/v0/css/public.css?t=20140212"  />
<title>情人节专题</title>
<style>
 img{border:none;}
        ul,li{
	        margin:0;
	        padding:0;
        }
        li{
	        list-style:none;
	        float:left;
	        display:inline;
	        margin-right:10px;
        }
        #imglist img{150px;height:120px;}
        #imgshow{
	        position:absolute;
	        border:1px solid #ccc;
	        background:#333;
	        padding:5px;
	        color:#fff;
	        display:none;
	    }

</style>
<script src="http://s1.hqbcdn.com/??lib/jquery/jquery-1.7.2.min.js,lib/jquery/jquery.cookie.js,lib/jquery/jquery-easing.1.3.js,lib/jquery/jquery.lazyload.js?t=20130703" type="text/javascript"></script>
<!--<script type="text/javascript" src="showImages.js"> </script>-->
<script type="text/javascript" src="showImages2.js"> </script>
<script type="text/javascript">


$(document).ready(function () {
        $.showImages("imglist");
    });
 </script>
</head>
<body>
<div>
	<ul class="cfix" id="imglist">
    	<li><img src="http://www.jquery001.com/images/demo/35624390.jpg" width="80" height="80"/></li>
        <li><img src="http://www.jquery001.com/images/demo/35624390.jpg"  width="80" height="80" /></li>
    </ul>
</div>

</body>
</html>

 插件代码:

$.extend({
	showImages: function(imglist){
	   var xOffset = 10;
	   var yOffset = 30;
	   var img = $("#"+imglist).find('img');
		$(img).hover(
			function(e){
				var _src = $(this).attr('src');	
				
				$("<img id='imgshow' src='" + _src + "' />").appendTo("body"); 
				$('#imgshow').css("top", (e.pageY - xOffset) + "px") 
				.css("left", (e.pageX + yOffset) + "px") .fadeIn("fast");
				
			},
				function(){
				$("#imgshow").remove(); 
		});	
		$(img).mousemove(
				function(e){
				$('#imgshow').css("top", (e.pageY - xOffset) + "px") 
				.css("left", (e.pageX + yOffset) + "px");
				}
		);	
	}
})

 mousemove事件:

鼠标跟随当前事件移动

原文地址:https://www.cnblogs.com/huanhuan8808/p/3598060.html