码迷,mamicode.com
首页 > 编程语言 > 详细

每天一个JavaScript实例-点击图片显示大图

时间:2014-10-27 17:48:10      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   os   ar   java   for   

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>每天一个JavaScript实例-点击图片显示大图</title>
<style>
	img{padding:5px;width:100px;height:auto;}
	#outer{
		width:100%;
		height:100%;
	}
	.overlay{
		background-color:#000;
		opacity: .7;
		filter:alpha(opacity=70);
		position: fixed;
		top:0;
		left:0;
		width:100%;
		height:100%;
		z-index: 10;
	}
	.overlayimg{
		position: absolute;
		z-index: 11;
		left:50px;
		top:30px;
		width:auto;
	}
</style>
<script>
function expandPhoto(){
	var overlay = document.createElement("div");
	overlay.setAttribute("id","overlay");
	overlay.setAttribute("class","overlay");
	document.body.appendChild(overlay);

	var img = document.createElement("img");
	img.setAttribute("class","overlayimg");
	img.src = this.getAttribute("src");
	document.getElementById("overlay").appendChild(img);

	img.onclick = restore;
}
function restore(){
	document.body.removeChild(document.getElementById("overlay"));
	document.body.removeChild(document.getElementById("img"));
}
window.onload = function(){
	var imgs = document.getElementsByTagName("img");
	imgs[0].focus();
	for(var i = 0;i<imgs.length;i++){
		imgs[i].onclick = expandPhoto;
		imgs[i].onkeydown = expandPhoto;
	}

}
</script>
</head>

<body>

<div id = "outer">
	<p>点击图片</p>
	<img src="http://e.hiphotos.baidu.com/image/pic/item/77094b36acaf2edde7684cc38e1001e93901937a.jpg" />
	<img src="http://e.hiphotos.baidu.com/image/pic/item/77094b36acaf2edde7684cc38e1001e93901937a.jpg" />	
	
</div>

</body>
</html>

每天一个JavaScript实例-点击图片显示大图

标签:style   blog   http   io   color   os   ar   java   for   

原文地址:http://blog.csdn.net/waiting7436/article/details/40508487

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!