实例如下所示:
<!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>图片提示</title>
<!--jQuery -->
<script src="../jquery.min.js"type="text/javascript"></script>
<style type="text/css">
body{
margin:0;
padding:40px;
background:#fff;
font:80% Arial, Helvetica, sans-serif;
color:#555;
line-height:180%;
}
img{border:none;}
ul,li{
margin:0;
padding:0;
}
li{
list-style:none;
float:left;
display:inline;
margin-right:10px;
border:1px solid #AAAAAA;
}
/* tooltip */
#tooltip{
position:absolute;
border:1px solid #ccc;
background:#333;
padding:2px;
display:none;
color:#fff;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
var x=1,y=1;
var myHref;
$("a[class=tooltip]").mouseover(function(e){//鼠标悬停的时候
myHref=this.href;//获取大图片
var $div=$("<div id='tooltip'><img src='"+myHref+"'></img></div>");//创建一个div
$("body").append($div);//把div添加到body中
$("#tooltip").css({
top:e.pageY+y+"px",
left:e.pageX+x+"px"
}).show("slow");
}).mouseout(function(e){//鼠标移开的时候
$("#tooltip").remove();
}).mousemove(function(e){//鼠标移动的时候
$("#tooltip").css({
top:e.pageY+y+"px",
left:e.pageX+x+"px"
}).show("slow");
})
});
</script>
</head>
<body>
<ul>
<li><a href="02121.png" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="tooltip" ><img src="02121.png" /></a></li>
<li><a href="02121.png" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="tooltip" ><img src="02121.png" /></a></li>
<li><a href="02121.png" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="tooltip" ><img src="02121.png" /></a></li>
<li><a href="02121.png" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="tooltip" ><img src="02121.png" /></a></li>
</ul>
<br/><br/><br/><br/>
<br/><br/><br/><br/>
</body>
</html>
以上这篇JavaScript通过mouseover()实现图片变大效果的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持天达云。