docs(demos): add scrollbar fix for api demos

This commit is contained in:
Drew Rygh
2015-12-28 12:22:14 -06:00
parent f82904fe51
commit 5bd6f377d1
2 changed files with 51 additions and 0 deletions

6
demos/scrollbar-fix.css Normal file
View File

@ -0,0 +1,6 @@
body.has-scrollbar scroll-content {
margin-right: -15px;
}
body.has-scrollbar ion-menu scroll-content {
margin-right: 0;
}

45
demos/scrollbar-fix.js Normal file
View File

@ -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);
}
})();