Here's some code that demonstrates what you want to do.
Note: I made a small change for the code in the script tag to fix an issue.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Test Rollover Popups</title>
<style type="text/css">
a.roll{cursor: pointer;}
a .rollContent{display: none;}
</style>
</head>
<body>
<div>
<div id="rollPop" style="position:absolute; display:none;">x</div>
<a class="roll">
<img alt="news"
src="http://www.battle.net/images/battle/diablo2/images/menu/menu-news-off.gif"
onmouseout="this.src='http://www.battle.net/images/battle/diablo2/images/menu/menu-news-off.gif'"
onmouseover="this.src='http://www.battle.net/images/battle/diablo2/images/menu/menu-news-ovr.gif'" />
<div class="rollContent">
<img src="http://www.battle.net/images/battle/diablo2exp/images/arreat-summit.gif" alt="arreatSummit" />
</div>
</a>
<br /><br />
<a class="roll">
<img alt="basics"
src="http://www.battle.net/images/battle/diablo2/images/menu/menu-basics-off.gif"
onmouseout="this.src='http://www.battle.net/images/battle/diablo2/images/menu/menu-basics-off.gif'"
onmouseover="this.src='http://www.battle.net/images/battle/diablo2/images/menu/menu-basics-ovr.gif'" />
<div class="rollContent">
<img src="http://www.battle.net/images/battle/diablo2exp/images/arreat-summit.gif" alt="arreatSummit" />
</div>
</a>
<br />
<script type="text/javascript">
(function() {
var pop = document.getElementById("rollPop");
var popStyle = pop.style;
var anchors = document.getElementsByTagName("a");
function showRoll(e) {
if(!e) e = window.event;
var o = e.target? e.target: e.srcElement;
while(!o.className || o.className!="roll") o = o.parentNode;
o = o.lastChild;
while(o.className!="rollContent") o = o.previousSibling;
pop.replaceChild(o.cloneNode(true), pop.firstChild);
popStyle.display = "block";
popStyle.top = (e.pageY? e.pageY: e.clientY)+15 + "px";
popStyle.left = (e.pageX? e.pageX: e.clientX)+15 + "px";
}
function hideRoll(e) {
popStyle.display = "none";
}
function moveRoll(e) {
if(!e) e = window.event;
popStyle.top = (e.pageY? e.pageY: e.clientY)+15 + "px";
popStyle.left = (e.pageX? e.pageX: e.clientX)+15 + "px";
}
for(var i=0, n=anchors.length; i<n; ++i) if(anchors[i].className=="roll") {
if(window.addEventListener) {
anchors[i].addEventListener("mouseover", showRoll, false);
anchors[i].addEventListener("mouseout", hideRoll, false);
anchors[i].addEventListener("mousemove", moveRoll, false);
}
else {
anchors[i].attachEvent("onmouseover", showRoll);
anchors[i].attachEvent("onmouseout", hideRoll);
anchors[i].attachEvent("onmousemove", moveRoll);
}
}
})();
</script>
</div>
</body>
</html>
Bookmarks