鼠标移动到不同图像上,在同一处显示相关的信息
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Multiple Link , single rollover</title>
<style type="text/css">
body {
background-color: #ec9;
}
img {
border-width: 0;
}
#captionDiv {
float: right; /*定义元素在哪个方向浮动 */
width: 210px;
margin: auto 50px; /* 外边距 */
}
#captionField {
margin: 20px auto;
width: 208px;
height: 27px;
}
#inventionDiv {
width: 375px;
margin-left: 20px;
}
#heading {
margin-bottom: 20px;
width: 375px;
height: 26px;
}
</style>
<script type="text/javascript">
/* 注意rolloverInit是绑定,所以不需要加() */
window.onload = rolloverInit;
function rolloverInit() {
for(i=0;i<document.links.length;i++) {
var linkObj = document.links[i];
if(linkObj.className) {
var imgObj = document.getElementById(linkObj.className);
if(imgObj) {
setupRollover(linkObj , imgObj);
}
}
}
}
function setupRollover(thisLink , textImage) {
thisLink.changeImage = textImage;
thisLink.outImage = new Image();
thisLink.outImage.src = textImage.src;
thisLink.overImage = new Image();
thisLink.overImage.src = "images/" + thisLink.id + "Text.gif";
thisLink.onmouseout = function() {
thisLink.changeImage.src = thisLink.outImage.src;
}
thisLink.onmouseover = function() {
thisLink.changeImage.src = thisLink.overImage.src;
}
}
</script>
</head>
<body>
<div id="captionDiv">
<img src="images/DaVinci.jpg" width="144" height="219" alt="DaVinci"/><BR/>
<img src="images/bg.gif" id="captionField" alt="Text Field"/>
</div>
<div id="inventionDiv">
<img src="images/leoText.gif" id="heading" alt="Leonardo's Inbentions"/><BR/>
<a href="flyPage.html" class="captionField" id="flyer">
<img src="images/flyer.gif" width="293" height="165" alt="Flying Machine" id="flyerImg"/>
</a><BR/>
<a href="tankPage.html" class="captionField" id="tank">
<img src="images/tank.gif" width="325" height="92" alt="Tank" id="tankImg"/>
</a><BR/>
<a href="heliPage.html" class="captionField" id="helicopter">
<img src="images/helicopter.gif" width="224" height="160" alt="Helicopter" id="helicopterImg"/>
</a>
</div>
</body>
</html>