PDA

View Full Version : when show layer no scrolling main page



imogeen
05-09-2007, 07:31 PM
Hello,
I'm making a portfolio site for my photo's and stuggeling with a layer. I managed to modify it to my likings a whole lot with help from people, i'm not very good with java at all. As far as i came, there is still one thing that i would like to add to this script.

When the layer is shown, i would like the scrollbar on the right of the main page (where the layer is inbedded) to be gone (no scrolling). If the layer is hidden (by klicking the link to do so) the scrollbar is back.

The code from the show/hide layer goes in <head>;

<script type="text/javascript">
<!--
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
if(document.layers) //NN4+
{
document.layers[szDivID].visibility = iState ? "show" : "hide";
}
else if(document.getElementById) //gecko(NN6) + IE 5+
{
var obj = document.getElementById(szDivID);
obj.style.visibility = iState ? "visible" : "hidden";
}
else if(document.all) // IE 4
{
document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
}
}
// -->
</script>

Code that goes in body;

<div ID="demodiv" class="demo">there is a lot in here but i will spare you guys.</div>

and the links that show/hide the layer;
<a href="#" onClick="toggleBox('demodiv',0);" value="Hide Div">[x]</a>
<a href="#" onClick="toggleBox('demodiv',1);" value="Show Div">show</a>

the site; http://www.greyburn.net
I really hope someone is a genius:)
Thank you!

jscheuer1
05-09-2007, 09:20 PM
I only know how to do this in modern browsers (gecko(NN6) + IE 5+). It may only be able to be done in modern browsers. And, it varies, how it is done by DOCTYPE. Since you are using no DOCTYPE, you could do it like so:


else if(document.getElementById) //gecko(NN6) + IE 5+
{
var obj = document.getElementById(szDivID);
obj.style.visibility = iState ? "visible" : "hidden";
if(document.getElementsByTagName)
document.getElementsByTagName('body')[0].style.overflow = iState ? 'hidden' : (window.opera? 'inherit' : '');
}

If you were to use a DOCTYPE that turns on standards or almost standards mode, use 'html' instead of 'body'.

imogeen
05-09-2007, 09:35 PM
Aaah yes, great! This works, but only when i close the layer and open it again. The layer is visible (loaded?) from the start, and then still the scroll is there.

Here you can see your script add working; http://www.greyburn.net
Is there a way to also get rid of the scroll at start of page?

jscheuer1
05-09-2007, 09:45 PM
<script type="text/javascript">
<!--
if(document.getElementsByTagName)
onload=function(){
document.getElementsByTagName('body')[0].style.overflow = 'hidden';
};
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
if(document.layers) //NN4+
{
document.lay . . .

imogeen
05-09-2007, 10:23 PM
Excellent! Thank's alot:)