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
https://forums.phpfreaks.com/topic/44964-positioning-elements-using-div/
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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.