Jquery 下实现 图片大图预览效果

时间:2023-03-09 04:38:51
Jquery 下实现 图片大图预览效果
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Examples</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
<script src="http://cdn.bootcss.com/jquery/3.1.0/jquery.min.js"></script>
<script src="//cdn.bootcss.com/jquery/3.1.0/jquery.js"></script>
</head>
<style type="text/css">
ul li{ line-height: 1px;
margin:3px;
display:inline-block;
}
</style> <body>
<div class="img">
<ul>
<li><a href="./i1.jpg" class="tooltip" title="苹果 ipad"><img src="./i1.jpg" alt="mac ipad" width="100" height="100" /></a></li>
<li><a href="./i2.jpg" class="tooltip" title="苹果 ipad"><img src="./i2.jpg" alt="mac ipad" width="100" height="100" /></a></li>
</ul>
</div> <script type="text/javascript">
$(function(){
var x=8;
var y=10;
$("a.tooltip").mouseover(function(e){
this.myTitle=this.title;
this.title="";
var imgtitle=this.myTitle?"<br/>"+this.myTitle:"";
var tooltip="<div id='tooltip'><img src='"+this.href+"' alt='产品预览图' />"+imgtitle+"</div>";
$("body").append(tooltip);
$("#tooltip").css({"top":(e.pageY+y)+"px","left":(e.pageX+x)+"px"}).show("fast");
}).mouseout(function(){
this.title=this.myTitle;
$("#tooltip").remove();
}).mousemove(function(e){
$("#tooltip").css({"top":(e.pageY+y)+"px","left":(e.pageX+x)+"px"});
})
})
</script>
</body>
</html>