faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

41 of 97 people (42%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I resize a DIV in the document like a frame in a frameset?

Apr 4th, 2008 19:59
ha mo, Colin Fraser, Stephan Boecker,


I dont know where I got this, but I know I got it from somewhere. 
<HTML>
<SCRIPT LANGUAGE="JavaScript">
<!--
ns = (document.layers)? true:false
mie = (document.all)? true:false
function init() {
        if (ns) block = document.blockDiv
        if (mie) block = blockDiv.style
}
function clipValues(obj,which) {
        if (ns) {
                if (which=="t") return obj.clip.top
                if (which=="r") return obj.clip.right
                if (which=="b") return obj.clip.bottom
                if (which=="l") return obj.clip.left
        }
        else if (mie) {
                var clipv = 
obj.clip.split("rect(")[1].split(")")[0].split("px")
                if (which=="t") return Number(clipv[0])
                if (which=="r") return Number(clipv[1])
                if (which=="b") return Number(clipv[2])
                if (which=="l") return Number(clipv[3])
        }
}
function clipTo(obj,t,r,b,l) {
        if (ns) {
                obj.clip.top = t
                obj.clip.right = r
                obj.clip.bottom = b
                obj.clip.left = l
        }
        else if (mie) obj.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)"
}
function clipBy(obj,t,r,b,l) {
        if (ns) {
                obj.clip.top = clipValues(obj,'t') + t
                obj.clip.right = clipValues(obj,'r') + r
                obj.clip.bottom = clipValues(obj,'b') + b
                obj.clip.left = clipValues(obj,'l') + l
        }
        else if (mie) obj.clip = 
"rect("+(this.clipValues(obj,'t')+t)+"px 
"+(this.clipValues(obj,'r')+r)+"px 
"+Number(this.clipValues(obj,'b')+b)+"px 
"+Number(this.clipValues(obj,'l')+l)+"px)"
}
function grow() {
        if (clipValues(block,'r')<300) {
                clipBy(block,0,5,0,0)
                setTimeout("grow()",30)
        }
}
function shrink() {
        if (clipValues(block,'r')>25) {
                clipBy(block,0,-5,0,0)
                setTimeout("shrink()",30)
        }
}
//-->
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" onLoad="init()">
<DIV ID="blockDiv" STYLE="position:absolute; left:150; top:80; 
width:200; height:100; clip:rect(0,50,100,0); background-color:#FF0000; 
layer-background-color:#FF0000;">
</DIV>
<P><A HREF="javascript:grow()">Grow to 300</A>
<BR><A HREF="javascript:shrink()">Shrink right edge to 25</A>
</BODY>
</HTML>
This may help answer your question.  
It works, btw, I know I did not write this originally, too much in the 
way of capital letters all over the place.
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com