Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

resizing a <div>

Status
Not open for further replies.

secretsquirrel

Programmer
Mar 22, 2001
202
GB
hi guys, i've got the following page which contains a drag and drop <div>.

i've been asked to add a handle in the bottom right corner of it which, when dragged, will resize the <div> - much like resizing a browser window.

i've put in an image in the corner to use as the handle, but i don't know how to implement the resizing. at the moment, the handle just drags annd drops like the rest of the layer.

can anyone suggest anything?

---------------------------------------

<HTML>
<HEAD>
<TITLE>resize</TITLE>

<STYLE TYPE=&quot;text/css&quot;><!--
.text10 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; background-color: #EFEFEF; line-height: 14px; padding-left: 3px; padding-right: 3px }
.drag { background-color: #EFEFEF; position: absolute; padding: 3px; border: 1px solid #CCCCCC }

INPUT { font-family: Verdana; font-size: 10px; }
-->
</STYLE>

<SCRIPT LANGUAGE=&quot;JavaScript&quot; ID=code>
// this code allows any absolutely positioned element to be dragged

var dragElmt = null // track current item

function doMouseMove()
{
// check if mouse button is down and if an element is being dragged
if ((1 == event.button) && (dragElmt != null))
{
// move the element to where the mouse is in the document
var intTop = event.clientY + document.body.scrollTop;
var intLeft = event.clientX + document.body.scrollLeft;

// calculate what element the mouse is actually in
var intLessTop = 0;
var intLessLeft = 0;
var currElmt = dragElmt.offsetParent;
while (currElmt.offsetParent != null)
{
intLessTop += currElmt.offsetTop;
intLessLeft += currElmt.offsetLeft;
currElmt = currElmt.offsetParent;
}

// set new position
dragElmt.style.pixelTop = intTop - intLessTop - dragElmt.y;
dragElmt.style.pixelLeft = intLeft - intLessLeft - dragElmt.x;

event.returnValue = false;
}
}

function checkDrag(elCheck)
{
// check if the clicked element supports dragging
while (elCheck != null)
{
if (null != elCheck.getAttribute(&quot;dragEnabled&quot;))
return elCheck
elCheck = elCheck.parentElement
}
return null
}

function doMouseDown()
{
// store element on mousedown. called from click handler in code below
var currElmt = checkDrag(event.srcElement)
if (null != currElmt)
{
dragElmt = currElmt;

// determine where the mouse is in the element
dragElmt.x = event.offsetX
dragElmt.y = event.offsetY
var op = event.srcElement

// find real location in respect to element being dragged
if ((dragElmt != op.offsetParent) && (dragElmt != event.srcElement))
{
while (op != dragElmt)
{
dragElmt.x += op.offsetLeft
dragElmt.y += op.offsetTop
op = op.offsetParent
}
}
}
}

function doSelectStart()
{
// don't start text selections in dragged elements.
return (null == checkDrag(event.srcElement) && (dragElmt != null))
}

function LS_collapse(whichLayer,whichImage)
{
if (whichLayer.style.display == 'none')
{
whichLayer.style.display = 'block';
whichImage.src = &quot;shrink.gif&quot;;
} else {
whichLayer.style.display = 'none';
whichImage.src = &quot;grow.gif&quot;;
}
}

function LS_reset(whichHolder,l,t)
{
whichHolder.style.left = l;
whichHolder.style.top = t;
}

// Process mousemove.
document.onmousedown = doMouseDown;
document.onmousemove = doMouseMove;

// Reset element on mouseup.
document.onmouseup = new Function(&quot;dragElmt=null&quot;);
document.onselectstart = doSelectStart;

</SCRIPT>

<BODY BGCOLOR=&quot;#FFFFFF&quot;>

<DIV id=&quot;holder1&quot; class=&quot;drag&quot; style=&quot;width: 300px; left: 200px; top: 15px;&quot; dragEnabled>

<table width=&quot;100%&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<tr>
<td align=&quot;right&quot;>
<img src=&quot;reset.gif&quot; onClick=&quot;LS_reset(holder1,'200','15');&quot; onMouseDown=&quot;event.cancelBubble=true&quot;>
<img id=&quot;image1&quot; src=&quot;shrink.gif&quot; onClick=&quot;LS_collapse(layer1,image1)&quot; onMouseDown=&quot;event.cancelBubble=true&quot;>
</td>
</tr>
</table>

<div id=&quot;layer1&quot; align=&quot;center&quot;>

<table cellpadding=0 cellspacing=0 width=100% class=&quot;text10&quot;>
<tr>
<td class=&quot;text10&quot; width=&quot;32%&quot;>item 1</td>
<td><input type=&quot;text&quot;></td>
</tr>
<tr>
<td class=&quot;text10&quot; width=&quot;32%&quot;>item 2</td>
<td><input type=&quot;text&quot;> <input type=&quot;button&quot; value=&quot;Lookup&quot; onMouseDown=&quot;event.cancelBubble=true&quot;></td>
</tr>
<tr>
<td width=&quot;32%&quot;> </td>
<td align=&quot;right&quot;>
<img src=&quot;reset.gif&quot; id=&quot;sizer&quot; dragEnabled style=&quot;position: absolute;&quot;>
</td>
</tr>
</table>

</div>

</DIV>

</BODY>
</HTML>

---------------------------------------


thanks in advance,

ss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top