...

View Full Version : Change z-index?



Cris79
02-26-2003, 07:41 AM
Ok! this is p\my problem I have a drag and drop script like this:

<html><head>
<script language="JavaScript">
<!-- Hide
N = (document.all) ? 0 : 1;
var ob;
function MD(e) {
if (N) {
ob = document.layers[e.target.name];
X=e.x;
Y=e.y;
return false;
}
else {
ob = event.srcElement.parentElement.style;
X=event.offsetX;
Y=event.offsetY;
}
}
function MM(e) {
if (ob) {
if (N) {
ob.moveTo((e.pageX-X), (e.pageY-Y));
}
else {
ob.pixelLeft = event.clientX-X + document.body.scrollLeft;
ob.pixelTop = event.clientY-Y + document.body.scrollTop;
return false;
}
}
}
function MU() {
ob = null;
}

if (N) {
document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
}
document.onmousedown = MD;
document.onmousemove = MM;
document.onmouseup = MU;
// End -->
</script>
</head>

<body>
<div id="a" style="position:absolute;left:50;top:50; z-index:4;">
<img src="unu.gif" name="s">
</div>
<div id="b" style="position:absolute;left:50;top:100; z-index:3;">
<img src="doi.gif" name="d">
</div>
<div id="c" style="position:absolute;left:100;top:50; z-index:2;">
<img src="trei.gif" name="c">
</div>
<div id="d" style="position:absolute;left:100;top:100; z-index:1;">
<img src="patru.gif" name="h">
</div>
</body>
</html>

I want to chage z-index . In MD function I must place a command who change z-index of the curent div from let say z-index: 2 to z-index:4. :rolleyes:
How can I do this?
Thanks!!!

glenngv
02-26-2003, 08:47 AM
objectRef.style.zIndex = 1;

just a hint on accessing css properties in javascript:

the corresponding property (when accessed by javascript) for every 2-word attribute in CSS which is separated by hyphen (-), is the first word then the second word where the first letter is capitalized.

examples:
z-index -> zIndex
font-size -> fontSize

Cris79
02-26-2003, 09:52 AM
Thanks man!!! It was simple In MM function ob.zIndex = 1 and in MU function ob.zIndex=-1 and it works. :) Now the selectid pcture is always on top of the other. :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum