jquery实现鼠标滑过小图时显示大图的方法教程
本文实例讲述了jquery实现鼠标滑过小图时显示大图的方法。分享给大家供大家参考。具体实现方法如下:
代码如下:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title></title>
</head>
<style type="text/css">
li{list-style:none;float:left;margin-left:10px;}
</style>
<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script type="text/javascript">
var data = {
"images/11_s.jpg":["images/11_b.jpg","美人1"],
"images/22_s.jpg":["images/22_b.jpg","美人2"],
"images/33_s.jpg":["images/33_b.jpg","美人3"],
"images/44_s.jpg":["images/44_b.jpg","美人4"]
};
$(function(){
$.each(data,function(key,value){
//初始化最后一个p为隐藏
$("p").last().hide();
//创建小图的节点
var smallpath = $("<img src='" + key + "' />").css({"margin":"5px","padding":"2px","border":"1px solid #000"});
//设置大图地址和名称
bigimgpath = smallpath.attr("bigmappath",value[0]);
bigimgname = smallpath.attr("bigmapname",value[1]);
$("p").first().append(smallpath);
//小图上添加事件
smallpath.mouver(function(){
//最后一个p淡入效果
$("p").last().fadein("fast");
//获取大图地址
$("#show").attr("src",$(this).attr("bigmappath"));
//获取大图名称并设置样式
$("#imgtitle").text($(this).attr("bigmapname")).css({"background":"#ebf1de","padding":"10px","margin-bottom":"10px"});
});
smallpath.mouseout(function(){
$("p").last().fadeout("fast");
});
});
});
</script>
<body>
<p></p>
<p>
<img id="show" src="" />
</p>
</body>
</html>