鼠标放在小图片上显示大图标
2016-03-30 15:35
281 查看
<!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>
<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>
相关文章推荐
- js引用action层变量
- 某预约系统分析 > 某区公共自行车租车卡在线预约,关于如何提高成功概率
- PHP 打印函数之 print print_r
- 算法:每过多长时间时针和分针相遇一次
- 求大数阶乘算法(华为2015面试题)
- PostgreSQL C代码覆盖率测试(gcov, lcov)
- poj3461——Oulipo(KMP)
- 礼拜三log~CSS控制文本不换行+省略号 & li宽度无效的解决方法 & 在js中获取后台变量
- 【iOS开发新手上路】教你一步一步创建一个功能齐全的UITableViewController(上)
- MYSQL服务无法启动的原因
- 字节码基础:JVM字节码初探
- 从数字城市迈向智能城市
- Gibbs 采样完整解析与理解
- POJ1852-Ants
- debug运行正常,release报错
- Ubuntu系统版本升级
- 上传图片预览
- php curl函数实例
- iOS中UITableView的UITableViewStyleGrouped组间距
- Fortran 子程序