Jump to content

re size object


adam291086

Recommended Posts

i have this script, i am trying to make it so that if a user clicks and drags the bottom right hand cornor then the object will change size. At the moment it still moves th object instead of resize. Any help is apprciated

 

var ie=document.all;
var nn6=document.getElementById&&!document.all;
var isdrag=false;
var x,y;
var dobj;

function movemouse(e)
{
if (isdrag)
{
    dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
    dobj.style.top = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
    return false;
}
}

function movemouseenlarge(e)
{
alert("wanker");
   return false;
}

function selectmouse(e) {
var fobj = nn6 ? e.target : event.srcElement;
var topelement = nn6 ? "HTML" : "BODY";

while (fobj.tagName != topelement && fobj.className != "dragme")
{
fobj = nn6 ? fobj.parentNode : fobj.parentElement;
}
if (fobj.className=="dragme")
{
isdrag = true;
dobj = fobj;
tx = parseInt(dobj.style.left+0);
ty = parseInt(dobj.style.top+0);
x = nn6 ? e.clientX : event.clientX;
y = nn6 ? e.clientY : event.clientY;

if(y >=ty+parseInt(dobj.style.height)-10&&x >=tx+parseInt(dobj.style.width)-10)
{
document.onmousemove=movemouseenlarge;
return false;

}
else
    {
document.onmousemove=movemouse;
return false;
}
}
}
document.onmousedown=selectmouse;
document.onmouseup=new Function("isdrag=false");

Link to comment
Share on other sites

ok i've been playing with my script but now it will only work in ie.

var ie=document.all; 

var nn6=document.getElementById&&!document.all; 

var isdrag=false; 

var x,y; 

var dobj;  

var xDelta,yDelta;





function selectmouse(e) 

{  

var fobj = nn6 ? e.target : event.srcElement; 

var topelement = nn6 ? "HTML" : "BODY";  

while (fobj.tagName != topelement && fobj.className != "dragme") 

{ 

fobj = nn6 ? fobj.parentNode : fobj.parentElement; 

} 	

if (fobj.className=="dragme") 	

{ 	

isdrag = true; 	

dobj = fobj; 	



x = nn6 ? e.clientX : event.clientX; 	

y = nn6 ? e.clientY : event.clientY;



if(y >=parseInt(fobj.style.top)+parseInt(fobj.style.height)-20&&x >=parseInt(fobj.style.left)+parseInt(fobj.style.width)-20)

{

document.onmousemove=enlargebox; 	

return false; 	

}

else

{

document.onmousemove=movemouse; 	

return false; 	

}

} 

}



function movemouse(e) 

{ 

if (isdrag) 	

{   

//the difference between where the event happened and new mouse location 

xDelta = x - parseInt(nn6 ? e.clientX : event.clientX);

yDelta = y- parseInt(nn6 ? e.clientY : event.clientY);



x = nn6 ? e.clientX : event.clientX;

y = nn6 ? e.clientY : event.clientY;



dobj.style.left = parseInt(dobj.style.left)-xDelta;

dobj.style.top = parseInt(dobj.style.top)-yDelta;

return false; 	

} 

}



function enlargebox(e) 

{ 

if (isdrag) 	

{   

//the difference between where the event happened and new mouse location 

xDelta = x - parseInt(nn6 ? e.clientX : event.clientX);

yDelta = y- parseInt(nn6 ? e.clientY : event.clientY);



x = parseInt(nn6 ? e.clientX : event.clientX);

y = parseInt(nn6 ? e.clientY : event.clientY);



if(parseInt(dobj.style.height) - yDelta<=100 && parseInt(dobj.style.width) - xDelta>100)

{

    dobj.style.height = '100px';

    dobj.style.width = (parseInt(dobj.style.width) - xDelta) + 'px';

    return false; 

}



if(parseInt(dobj.style.height) - yDelta>100 && parseInt(dobj.style.width) - xDelta<=100)

{

    dobj.style.width = '100px';

    dobj.style.height = (parseInt(dobj.style.height) - yDelta) + 'px';

    return false; 

}



if(parseInt(dobj.style.height) - yDelta<=100 && parseInt(dobj.style.width) - xDelta<=100)

{

    dobj.style.width = '100px';

    dobj.style.height = '100px'

     isdrag=false;

}



if(parseInt(dobj.style.height) - yDelta>100 && parseInt(dobj.style.width) - xDelta>100)

{

dobj.style.width = parseInt(dobj.style.width)-xDelta;

dobj.style.height = parseInt(dobj.style.height)-yDelta;

return false; 

}

} 

}



document.onmousedown=selectmouse; 

document.onmouseup=new Function("isdrag=false"); 

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.