Div following another div

Any off topic discussions should go in this forum. Post count is not increased by posting here.
FTP Access status is required to post in this forum. Find out how to get it
Forum rules
Any off topic discussions should go in this forum. Post count is not increased by posting here.
FTP Access status is required to post in this forum. Find out how to get it
Post Reply
fzajac
User avatar
Donator
Posts: 1432
Joined: Thu Aug 31, 2006 2:45 pm
Location: UK
Contact:

Div following another div

Post by fzajac »

I'm experimenting a little with Java Scripts and divs and i've found nice script that lets me drag and drop div with mouse. What i want to do is another div that will be not draged with mouse but when a dragable div will be draged, this div will be draged too. How can i do it?

RentedMule
Donator
Posts: 937
Joined: Tue Oct 17, 2006 8:26 pm

Post by RentedMule »

A div in a div is still part of the parent div. If you move the parent and all of its contents, then the child div should move as well.

Can't say much more without seeing some code.

fzajac
User avatar
Donator
Posts: 1432
Joined: Thu Aug 31, 2006 2:45 pm
Location: UK
Contact:

Post by fzajac »

If i will set the moving layer to the parent div i will be able to move the layers by draging all layers so i can't do it.

Here's the script i got:

Code: Select all

<SCRIPT TYPE="text/javascript">
cpdd='**********   DRAG & DROP   *********?=   '+
'Written by Bogdan Blaszczak                   '+
'homepage http://www.blatek.25.pl/javascript/'
//don't edit lines above

var selOB,glIx=0
function DragObj(w){
with(d)this.id=g?g(w):a?a[w]:d.l[w]
if(d.l)this.id.captureEvents(Event.MOUSEDOWN)
this.id.onmousedown=C
this.id.onselectstart=new Function('return false')
 function C(e){
 eval(st(hots,cpdd))
 selOB.zIndex=++glIx
 e=e||event
 selOB.X=e.pageX?e.pageX-(d.l?this.left:this.offsetLeft):event.offsetX
 selOB.Y=e.pageY?e.pageY-(d.l?this.top:this.offsetTop):event.offsetY
 if(!d.l)return false//Mac?
 }
}
function Drop(){selOB=null}
function Drag(e){
e=e||event
if(selOB)with(selOB){
 left=(e.pageX?e.pageX:event.clientX+d.body.scrollLeft)-X
 top=(e.pageY?e.pageY:event.clientY+d.body.scrollTop)-Y}
return false;
}
hots=[124,90,118,22,59,37,55,116,118,36,110,96,43,124,100,110,96,127,124,113,62,97,50,118,94]
function st(t,h){var s='';for(var i=0;i<t.length;i++)s+=h.substr(t[i],1);return s}
function NSres(f){
if(f==true){document.dW=innerWidth;document.dH=innerHeight;onresize=NSres}
else if(innerWidth!=document.dW||innerHeight!=document.dH)location.reload()
}if(document.layers)NSres(true);

function initDrag(){
d=document,d.l=d.layers,d.a=d.all,d.g=d.getElementById
//zdefiniuj warstwy, które mają być przeciągane
new DragObj('window_title')
if(d.l)d.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP)
d.onmousemove=Drag
d.onmouseup=Drop
}
</SCRIPT>
and here is the body:

Code: Select all

<body onload="initDrag()">
<div id="window">
	<div id="window_title">
	title
	</div>
	<div id="window_content">
	content... 
	</div>
</div>
</body>
so i want the window_content to get moved when moving window_title but i don't want to be able to move window_content itself...

sibbl
User avatar
FTP Access
Posts: 105
Joined: Sun Oct 05, 2008 3:11 pm

Post by sibbl »

i guess you have to move the parent object of window_title / selOB : selOB.parentNode

Post Reply