Thursday, August 26, 2010

javascript that will hide and display the body scrollbar using shadowbox



function scrollBackground() {
// Disables background screen scrolling while viewing shadowbox popups

// Copyright 2010 Peter Smith
// Usage: Allowed if copyright statement remains

// add the following to the Shadowbox.init ({})
// onOpen: scrollBackground, onClose: scrollBackground

// Get a reference to the HTML element
var objHTML = document.getElementsByTagName("html").item(0);

// Hide/show scrollbar
if (objHTML.style.overflow == "hidden") {
objHTML.style.overflow = "auto";
} else {
objHTML.style.overflow = "hidden";
// Hiding the vertical scrollbar and having the webpage centered makes the content jump across by the amount of the scrollbars width
// this adjust that if html width is not set i.e. it only fires once.
if (objHTML.style.width == "") objHTML.style.width = "" + parseInt(objHTML.offsetWidth - 17) + "px";
}
}

No comments:

Post a Comment