views:

73

answers:

2

I have the following code:

<body>
    <div id="container" style="position:absolute; left:0px; top:0px; z-index:1;">
        <div id="div1" style="background-color:Red; position:absolute; left:0px; top:0px; width:256px; height:256px; z-index:0;" >&nbsp;</div>
        <div id="div2" style="background-color:Black; position:absolute; left:256px; top:0px; width:256px; height:256px; z-index:0;" >&nbsp;</div>
        <div id="div3" style="background-color:Green; position:absolute; left:512px; top:0px; width:256px; height:256px; z-index:0;" >&nbsp;</div>
        <div id="div4" style="background-color:Yellow; position:absolute; left:768px; top:0px; width:256px; height:256px; z-index:0;" >&nbsp;</div>
        <div id="div5" style="background-color:Blue; position:absolute; left:1024px; top:0px; width:256px; height:256px; z-index:0;" >&nbsp;</div>
    </div>

    <script type="text/javascript">
        <!--

        SET_DHTML("container");

        //-->
    </script> 
</body>

I want to drag the 'container' div such that all child divs are dragged at the same time. I can drag individual divs, but that is not what I want. Can a div drag child divs or do they have to be images?

I am using the WalterZorn drag drop API, but am open to using any API, script or whatever.

+1  A: 

I did something similar using Zorn's library and used Prototype together to try to make some sort of visio-like tool. I never finished it, but learned a lot in the process. It uses draggables, so maybe you'll make some use of the code. Just view the page source and it's all there.

Diodeus
I have to say that is quite impressive. The code that is responsible for auto arranging the lines that connect the boxes, did you write the code yourself?
Roberto Sebestyen
Yeah, I wrote it all myself. The line-routing was fun but not very scalable when the drawing increases in complexity. A good effect though :)
Diodeus
+1  A: 

The jQuery-UI Draggable works just fine for me and dead simple to set up. http://jqueryui.com/demos/draggable/ It works with your scenario, I just tested it.

Once you include jQuery and jQuery-UI do the following to turn your container DIV into a draggable DIV:

<script type="text/javascript">    

    //This makes sure that the code only runs once the whole
    //HTML document has been loaded into the Browser.
    $(document).ready(function(){
            $("#container").draggable();  //Intialize the Draggable ability
    });        
</script>
Roberto Sebestyen