From 5bd6f377d1e746fdfb5688c84f5025de579f4d2c Mon Sep 17 00:00:00 2001 From: Drew Rygh Date: Mon, 28 Dec 2015 12:22:14 -0600 Subject: [PATCH] docs(demos): add scrollbar fix for api demos --- demos/scrollbar-fix.css | 6 ++++++ demos/scrollbar-fix.js | 45 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 demos/scrollbar-fix.css create mode 100644 demos/scrollbar-fix.js diff --git a/demos/scrollbar-fix.css b/demos/scrollbar-fix.css new file mode 100644 index 0000000000..dd56aaad3f --- /dev/null +++ b/demos/scrollbar-fix.css @@ -0,0 +1,6 @@ +body.has-scrollbar scroll-content { + margin-right: -15px; +} +body.has-scrollbar ion-menu scroll-content { + margin-right: 0; +} \ No newline at end of file diff --git a/demos/scrollbar-fix.js b/demos/scrollbar-fix.js new file mode 100644 index 0000000000..2d6944b680 --- /dev/null +++ b/demos/scrollbar-fix.js @@ -0,0 +1,45 @@ +(function(){ + + function hasScrollbar() { + + if (typeof window.top.innerWidth === 'number') { + return window.top.innerWidth > window.top.document.documentElement.clientWidth; + } + + // rootElem for quirksmode + var rootElem = window.top.document.documentElement || window.top.document.body; + + // Check overflow style property on body for fauxscrollbars + var overflowStyle; + + if (typeof rootElem.currentStyle !== 'undefined') { + overflowStyle = rootElem.currentStyle.overflow; + } + + overflowStyle = overflowStyle || window.top.getComputedStyle(rootElem, '').overflow; + + // Also need to check the Y axis overflow + var overflowYStyle; + + if (typeof rootElem.currentStyle !== 'undefined') { + overflowYStyle = rootElem.currentStyle.overflowY; + } + + overflowYStyle = overflowYStyle || window.top.getComputedStyle(rootElem, '').overflowY; + + var contentOverflows = rootElem.scrollHeight > rootElem.clientHeight; + var overflowShown = /^(visible|auto)$/.test(overflowStyle) || /^(visible|auto)$/.test(overflowYStyle); + var alwaysShowScroll = overflowStyle === 'scroll' || overflowYStyle === 'scroll'; + + return (contentOverflows && overflowShown) || (alwaysShowScroll) + } + + + if (hasScrollbar() === true) { + setTimeout(function() { + var body = document.getElementsByTagName('body')[0]; + body.className = body.className + ' has-scrollbar'; + }, 500); + } + +})(); \ No newline at end of file