This article describes the method of implementing mouse sensing image display by JS. Share it for your reference. The specific implementation method is as follows:
Copy the code as follows:<!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>Mouse sensing image display effect</title>
<!--[if lte IE 6]>
<script language="Javascript">
var W3CDOM = (document.createElement() && document.getElementsByTagName());
window.onload = pinballEffect;
function pinballEffect()
{
if (!W3CDOM) return;
var allElements = document.getElementsByTagName('*');
var originalBackgrounds=new Array();
for (var i=0; i<allElements.length; i++)
{
if (allElements[i].className.indexOf('hovereffect') >= 0)
{
allElements[i].onmouseover = mouseGoesOver;
allElements[i].onmouseout = mouseGoesOut;
}
}
}
function mouseGoesOver()
{
originalClassNameString = this.className;
this.className += "lay-on";
}
function mouseGoesOut()
{
this.className = originalClassNameString;
}
pinballEffect();
</script>
<![endif]-->
<style type="text/css">
body {
background:#fff;
font:small/1.5 "安体", SimSun, serif;
_font-size:medium;
}
a img {
border:none;
}
ul,
li,
h5 {
list-style:none inside;
margin:0;
padding:0;
}
.recomm {
background:#999;
border:1px solid #666;
width:600px;
height:170px;
overflow:hidden;
padding:10px;
margin:0 auto;
position:relative;
}
.recomm ul {
border:1px solid #ffff;
border-left:none;
height:168px;
width:599px;
overflow:hidden;
*position:absolute; /* Solve the problem that overflow:hidden cannot hide elements correctly in IE*/
}
.recomm li {
float:left;
position:relative;
margin-right:-179px;
height:100%;
overflow:hidden;
white-space:nowrap;
text-align:center;
}
.recomm li img {
display:block;
border-left:1px solid #ffff;
width:248px;
height:168px;
}
.recomm li h5 {
position:absolute;
bottom:0;
left:0;
height:20px;
width:239px;
line-height:20px;
background:url(../images/1_211621.png) no-repeat;
display:none;
text-align:right;
padding-right:10px;
font-size:1em;
font-weight:normal;
}
.recomm li:hover, .recomm .lay-on {
width:249px;
margin-right:0;
}
.recomm li:hover h5, .recomm .lay-on h5 {
display:block;
}
</style>
</head>
<body>
<div>
<ul>
<li><a href="/"><img src="/images/m01.jpg" /></a>
<h5>Red Leaves Passing Love By <a href="/">Code Home</a> 2010.09.23</h5>
</li>
<li><a href="/"><img src="/images/m02.jpg" /></a>
<h5>Wild flowers bloom By <a href="/">Shanshan Film and Television Online</a> 2010.09.23</h5>
</li>
<li><a href="/"><img src="/images/m03.jpg" /></a>
<h5>The past is like tea By <a href="/">Code Home</a> 2010.09.23</h5>
</li>
<li><a href="/"><img src="/images/m04.jpg" /></a>
<h5>Raise flowers bloom By <a href="/">Colorful Film and Television</a> 2010.09.23</h5>
</li>
<li><a href="/"><img src="/images/m05.jpg" /></a>
<h5>Rose Love By <a href="/">Code Home</a> 2010.09.23</h5>
</li>
<li><a href="/"><img src="/images/m09.jpg" /></a>
<h5>Little Daisy By <a href="/">Shanshan Film and Television</a> 2010.09.23</h5>
</li>
</ul>
</div>
</body>
</html>
I hope this article will be helpful to everyone's JavaScript programming.