PDA

View Full Version : resizing layers


Brian Nickel
21.05.2001, 16:07
It is easy to resize layers in IE and NS6, but I'm having trouble with NS4. The way I'm doing it, I use a table to control width, but is interferes with inline styles, is there a better way?

ScriptGuru={
getName:function(){return 'Brian Nickel';},
getEmail:function(){return '[url:r5c1hhwqgr]scriptguru@f2s.com[/url:r5c1hhwqgr]';},
getURL:function(){return '[url:r5c1hhwqgr]http://www.scriptguru.f2s.com[/url:r5c1hhwqgr]';}
};

bratta
22.05.2001, 13:42
I assume you mean changing the width of for intance a text block. You can't really do that in NS4 after pageload so you have to cheat a little. There are as far as I know basically 3 ways to do this. The bad thing is that 2 of them require a write to the layer so you have to have the content in the layer as a string. I have made up a quick example of the 2 most usefull ways:


<script>
function resize1(){
lay=document.layers.divTest.document
lay.clip.right=300 //YOU DON'T NEED THIS LINE.
lay.write("<span class='clNewWidth'>"+content+"</span>")
lay.close()
}
function resize2(w){
lay=document.layers.divTest
lay.document.write('')
lay.document.close()
lay.clip.right=w
lay2=new Layer(w,lay)
lay2.document.write(content)
lay2.document.close()
lay2.visibility="show"
self.status=lay.document.layers.length
}

content="content content content content content content content content content content content content content content content content"
</script>
<style>
.clNewWidth{width:300}
#divTest{position:absolute; width:200; height:250}
</style>
<div id="divTest"><script>document.write(content)</script></div>

























resize1 - width spesified in class (#)



resize2(100) (#)


resize2(400) (#)

When you write to a layer it looses all the current style settings so you have to reset them by writing a span or something with a class assigned to it (do not use inline styles). Since you have to use a class you have to predefine the width.

The second option is to use the Layer constructor as you see in resize2. It gives you a little more flexibility but has it's downsides.

The third way it to load content into the layer from an external file. But then you have to have the content in another file.

Hope this helped.

-Thomas Brattli-
http://www.bratta.com/
http://www.dhtmlcentral.com/

Brian Nickel
23.05.2001, 17:04
Thanks, resize2 works great.

ScriptGuru={
getName:function(){return 'Brian Nickel';},
getEmail:function(){return '[url:1gxw94dg44]scriptguru@f2s.com[/url:1gxw94dg44]';},
getURL:function(){return '[url:1gxw94dg44]http://www.scriptguru.f2s.com[/url:1gxw94dg44]';}
};