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
| <html>
<head>
<!--*********************************************-->
<!-- Permettre le dessin d'un rectangle -->
<!--*********************************************-->
<script language="JavaScript" type="text/JavaScript">
function Draw(c){
var startPos=new Array();
var endPos=new Array();
var container=null;
construct(c);
function construct(c)
{
container=(typeof c=="undefined")?getDefaultContainer():c;
}
function getDefaultContainer()
{
var temp=document.createElement("div");
document.body.appendChild(temp);
return temp;
}
function SourisDown(evt)
{
var e = null;
var newX=0;
var newY=0;
// IE
if(document.all)
{
e = window.event;
newX = e.x;
newY = e.y;
}
// Mozilla
else
{
e = evt;
newX = e.clientX;
newY = e.clientY;
}
startPos[0]=newX;
startPos[1]= newY;
}
function SourisUp(evt)
{
fix_start=false;
var e = null;
var newX=0;
var newY=0;
// IE
if(document.all)
{
e = window.event;
newX = e.x;
newY = e.y;
}
// Mozilla
else
{
e = evt;
newX = e.clientX;
newY = e.clientY;
}
endPos[0]=newX;
endPos[1]= newY;
alert(startPos+" - "+endPos);
}
Draw.prototype.clear = function (){
container.innerHTML='';
}
Draw.prototype.line=function (x1,y1,x2,y2,t,c) {
if (typeof t=="undefined") {t=1;}
if (x1==x2) {x2+=t;} // add thickness
if (y1==y2) {y2+=t;} // add thickness
var div=document.createElement("div");
div.style.position="absolute";
div.style.width= Math.abs(x1-x2)+"px";
div.style.height=Math.abs(y1-y2)+"px";
div.style.left=x1+"px";
div.style.top =y1+"px";
div.style.backgroundColor=(typeof c=="undefined"?"#000000":c);
div.style.cursor="pointer";
container.appendChild(div);
}
Draw.prototype.rectangle=function (x,y,w,h,c) {
line(x,y,x+w,y+h,1,c);
}
container.onmouseup=SourisUp;
container.onmousedown=SourisDown;
}
</script>
<!--*********************************************-->
<!-- Fin du dessin d'un rectangle -->
<!--*********************************************-->
</head>
<body>
<div id="e">
<img src='rectangle/test.jpg' name='obj' id='obj' width='700' height='560' border='1'/>
</div>
<script language="JavaScript" type="text/JavaScript">
var dessin = new Draw(document.getElementById("e"));
</script>
</body>
</html> |
Partager