1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script></script>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title></title>
<style>
.cible1
{
position : relative;
float : left;
top : 500px;
padding:10px;
border-style : solid;
margin : 5px;
border-width : 1px;
}
.popup
{
position : absolute;
width : 470px;
height : 470px;
border-style : solid;
border-width : 1px;
overflow:hidden;
left : -10000px;
z-index : 100;
}
</style>
</head>
<body onload="load()">
<script>
function Target(id, picture, width, height)
{
this.id = id;
this.ref = null;
this.width = width;
this.height = height;
this.picture = picture;
}
Target.prototype.getHeight = function()
{
var elt = document.getElementById(this.id);
return elt.offsetHeight;
}
Target.prototype.getWidth = function()
{
var elt = document.getElementById(this.id);
return elt.offsetWidth;
}
function TargetList(popupId, popupWidth, popupHeight)
{
this.popupId = popupId;
this.popupWidth = popupWidth;
this.popupHeight = popupHeight; this.items = new Array();
this.currentIndex = -1;
}
TargetList.prototype.addTarget = function(id,picture,width,height)
{
var item = new Target(id,picture,width,height);
item.index = this.items.length; var elt = document.getElementById(id);
this.items.push(item);
}
TargetList.prototype.hidePopup = function()
{
if (this.currentIndex != -1)
{
document.getElementById(this.popupId).style.left=-10000+"px";
this.currentIndex = -1;
} }
TargetList.prototype.selectTarget = function(index)
{
if (this.currentIndex != index)
{
if ((index >=0) && (index < this.items.length))
{
document.getElementById(this.popupId).innerHTML='<img src="'+this.items[index].picture+'">';
this.currentIndex = index;
}
} }
TargetList.prototype.showPopup = function(x,y)
{
var elt = document.getElementById(this.popupId);
elt.style.left=x+5+"px";
elt.style.top=y-this.popupHeight+"px";
}
TargetList.prototype.findTarget = function(x,y)
{
var index = -1;
for (var i=0; i < this.items.length; i++)
{
var position = findPosition(this.items.id);
if ((x >= position.x) && (x < position.x+this.items.getWidth()) && (y >= position.y) && (y < position.y+this.items.getHeight()))
{
index = i;
break;
}
}
return index;
}
var targetList = new TargetList("popup",250,213);
function strToNumber(value)
{
var nbr = parseInt(value);
if (isNaN(nbr)) { nbr = 0;}
return nbr;
}
function mousePosition(e)
{
var result = new Array();
result["x"] = 0;
result["y"] = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY) {
result["x"] = e.pageX;
result["y"] = e.pageY;
}
else if (e.clientX || e.clientY) {
result["x"] = e.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft;
result["y"] = e.clientY + document.body.scrollTop
+ document.documentElement.scrollTop;
}
return result;
}
function findPosition(id)
{
var elt = document.getElementById(id);
var result = new Array();
result["x"] = 0;
result["y"] = 0;
while (elt)
{
result["x"] += elt.offsetLeft;
result["y"] += elt.offsetTop;
elt = elt.offsetParent;
}
return result;
}
function mouseMove(e)
{
var mouse = mousePosition(e);
index =targetList.findTarget(mouse.x,mouse.y);
if (index != -1)
{
targetList.selectTarget(index);
targetList.showPopup(mouse.x,mouse.y);
}
else
{
targetList.hidePopup();
}
}
function load()
{
targetList.addTarget("cible1","job_pour_toi.jpg",250,213);
document.onmousemove=mouseMove;
}
</script>
<div class="popup" id="popup"></div>
<div class="cible">
<img id="cible1" src="job_pour_toi.jpg" width="470"></div>
</body>
</html> |
Partager