HTML5网页设计

图片效果

JS实现鼠标经过小图出现大图提示效果

时间:2014-11-28 17:32来源:未知作者:点击:
javascript和css实现当鼠标经过略缩图时出现大图提示效果

<!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" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title>JS实现鼠标经过小图出现大图提示效果</title>
</head>
<body>
<style type="text/css">
#demo{overflow:hidden;width:120px;text-align:center;padding:10px;}
#demo img{border:none;width:100px;height:100px;border:5px solid #f4f4f4}
#enlarge_images{position:absolute;display:none;z-index:2;border:5px solid #f4f4f4}</style>
<div id="demo" style="overflow:hidden;width:120px;text-align:center;padding:10px">
	<img src="http://www.shejicool.com/uploads/allimg/201110/2345324436-12.jpg" /></div>
<div id="enlarge_images">&nbsp;</div>
<script>
var demo = document.getElementById("demo");
var gg = demo.getElementsByTagName("img");
var ei = document.getElementById("enlarge_images");
for(i=0; i<gg.length; i++){
	var ts = gg[i];
	ts.onmousemove = function(event){
		event = event || window.event;
		ei.style.display = "block";
		ei.innerHTML = '<img src="' + this.src + '" />';
		ei.style.top  = document.body.scrollTop + event.clientY + 10 + "px";
		ei.style.left = document.body.scrollLeft + event.clientX + 10 + "px";
	}
	ts.onmouseout = function(){
		ei.innerHTML = "";
		ei.style.display = "none";
	}
	ts.onclick = function(){
		window.open( this.src );
	}
}
</script><br />
<p>
	本资源来自<a href="http://www.shejicool.com">设计酷</a> - 更多优质设计素材及资源请访问<a href="http://www.shejicool.com">http://www.shejicool.com</a></p>
</body>
</html>
上一篇:上一篇:鼠标可控制上下图片滚动代码 上一篇:下一篇:jQuery图片上下滚动效果
阅完本篇文章?您还可以: 收藏本文 文章挑错 朋友推荐