Skip to content

Instantly share code, notes, and snippets.

@mutuadavid93
Created July 5, 2017 14:04
Show Gist options
  • Save mutuadavid93/a00776861994b833ba114e24cf086152 to your computer and use it in GitHub Desktop.
Save mutuadavid93/a00776861994b833ba114e24cf086152 to your computer and use it in GitHub Desktop.
// ## Add a ScrollBar to a Page using jQuery
// ## Add a ScrollBar to an Element using jQuery
// ## Add a ScrollBar to a Div using javascript
// ## Add a ScrollBar to a SharePoint Master Pages using jQuery
// ## START Adding a ScrollBar on PAGE
// Get the Open Window Height then Compare it to Parent Div height
if ($('div#ms-designer-ribbon').html()) {
//Don't Show ScrollBar
} else {
// Show The Scroll Bar
var windowHeight = $(window).height();
var outerHight = $(window).outerHeight(),
viewOffset = (outerHight - 10),
outerElemHight = $('div#s4-workspace').outerHeight();
(outerElemHight > windowHeight) ? jQuery('div#s4-workspace').css({ "overflow-y": "scroll", "height": viewOffset }) : "";
// Even When Browser Window Is Resized, Set the Elem Heigh and ScrollBar
$(window).resize(function () {
var outerHight = $(window).outerHeight(),
windowHeight = $(window).height(),
viewOffset = (outerHight - 10),
$this = jQuery('div#s4-workspace');
outerElemHight = $('div#s4-workspace').outerHeight();
//(outerElemHight > windowHeight) ? $this.css({"overflow-y": "scroll", "height":outerHight}) : "";
if (outerElemHight > windowHeight) {
$this.css({ "overflow-y": "scroll", "height": viewOffset });
}
});
}// end if else
// ## END Adding a ScrollBar in Timesheet View
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment