Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide scrollbar when no scrolling is possible #1

Merged
merged 1 commit into from
Oct 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions simple-scrollbar.css
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
.ss-wrapper {
overflow : hidden;
height : 100%;
position : relative;
z-index : 1;
float: left;
overflow : hidden;
height : 100%;
position : relative;
z-index : 1;
float: left;
}

.ss-content {
height : 100%;
width : 100%;
padding : 0 32px 0 0;
position : relative;
right : -18px;
overflow : auto;
-moz-box-sizing : border-box;
box-sizing : border-box;
height : 100%;
width : 100%;
padding : 0 32px 0 0;
position : relative;
right : -18px;
overflow : auto;
-moz-box-sizing : border-box;
box-sizing : border-box;
}

.ss-scroll {
Expand All @@ -29,14 +29,18 @@
transition: opacity 0.25s linear;
}

.ss-hidden {
display: none;
}

.ss-container:hover .ss-scroll {
opacity: 1;
}

.ss-grabbed {
user-select: none;
-o-user-select: none;
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
-o-user-select: none;
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
}
12 changes: 9 additions & 3 deletions simple-scrollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,25 @@
this.scrollRatio = ownHeight / totalHeight;

raf(function() {
_this.bar.style.cssText = 'height:' + (ownHeight / totalHeight) * 100 + '%; top:' + (_this.el.scrollTop / totalHeight ) * 100 + '%;right:-' + (_this.target.clientWidth - _this.bar.clientWidth) + 'px;';
// Hide scrollbar if no scrolling is possible
if(_this.scrollRatio === 1) {
_this.bar.classList.add('ss-hidden')
} else {
_this.bar.classList.remove('ss-hidden')
_this.bar.style.cssText = 'height:' + (_this.scrollRatio) * 100 + '%; top:' + (_this.el.scrollTop / totalHeight ) * 100 + '%;right:-' + (_this.target.clientWidth - _this.bar.clientWidth) + 'px;';
}
});
}
}

function initAll() {
var nodes = d.querySelectorAll('*[ss-container]');

for (var i = 0; i < nodes.length; i++) {
initEl(nodes[i]);
}
}

d.addEventListener('DOMContentLoaded', initAll);
ss.initEl = initEl;
ss.initAll = initAll;
Expand Down
2 changes: 1 addition & 1 deletion simple-scrollbar.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.