Jump to content

positioning elements using div


suzzane2020

Recommended Posts

Hi,

 

    Iam working on drag and drop html control script. Here i have a list of html elements which can be dragged and dropped onto a dropable area.

so far so good. But i need to position these elements when i drop them

ie. I need to place them wherever i want in the dropable area.

hw can i do tht using the div tag.

 

Any help wud be appreciated

Thank You

Link to comment
Share on other sites

here is what I would do

but i'm just writting this free-hand so it may not work. you should be able to get the idea

 

<style type="css/text">

#movableDiv{
position: absolute;
/* original coordinates */
top: 50px; 
left: 50px
}

</style>

<script type="javascript">

function moveDiv(){

//do some sort of onClick thing to figure out where your mouse is 
// and where you want the top, left corner of the div to be

var newTop = 600;
var newLeft = 69;

document.getElementById('movableDiv').style.top = newTop + "px";
document.getElementById('movableDiv').style.left = newLeft + "px";

}
</script>


<div id="movableDiv">
  stuff inside div
</div>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.