Skip to content

Commit

Permalink
Fix a bug when scrollbar width is 0 (no mouse plugged or mobile usage)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien Grsmto committed Mar 17, 2015
1 parent 23449c6 commit b28992f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
7 changes: 4 additions & 3 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ <h2>Horizontal scroller</h2>
<a class="btn add-more-horiz" href="#">Add content</a>
<a class="btn toggle-width" href="#">Toggle width</a>
</div>
<div style="clear:both;"></div>

<!-- JavaScript -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="vendor/jquery-1.10.2.min.js"><\/script>')</script>

<script src="../dist/simplebar.min.js"></script>
<script src="../src/simplebar.js"></script>

<script>
$(document).ready(function() {
Expand All @@ -72,7 +73,7 @@ <h2>Horizontal scroller</h2>
// Demonstration of changing the vertical scroller content and dimensions.
$('.add-more').on('click', function(e){
e.preventDefault();
$('.demo1 .simplebar-content').append('<p class="odd">Additional content 1</p><p>Additional content 2</p><p p class="odd">Additional content 3</p><p>Additional content 4</p>');
$('.demo1').simplebar('getContentElement').append('<p class="odd">Additional content 1</p><p>Additional content 2</p><p p class="odd">Additional content 3</p><p>Additional content 4</p>');
$('.demo1').simplebar('recalculate');
});
$('.toggle-height').on('click', function(e){
Expand All @@ -87,7 +88,7 @@ <h2>Horizontal scroller</h2>
// Demonstration of changing the horizontal scroller content and dimensions.
$('.add-more-horiz').on('click', function(e){
e.preventDefault();
$('.demo2 .simplebar-content .boxes').append('<div class="box">A</div><div class="box">B</div><div class="box">C</div><div class="box">D</div>');
$('.demo2').simplebar('getContentElement').append('<div class="box">A</div><div class="box">B</div><div class="box">C</div><div class="box">D</div>');
$('.demo2').simplebar('recalculate');
});
$('.toggle-width').on('click', function(e){
Expand Down
2 changes: 1 addition & 1 deletion dist/simplebar.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SimpleBar.js - v1.1.1
* SimpleBar.js - v1.1.3
* Scrollbars, simpler.
* https://grsmto.github.io/simplebar/
*
Expand Down
4 changes: 2 additions & 2 deletions dist/simplebar.min.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url" : "http://github.com/grsmto/simplebar.git"
},
"homepage": "https://grsmto.github.io/simplebar/",
"version": "1.1.2",
"version": "1.1.3",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-cli": "~0.1.13",
Expand Down
14 changes: 9 additions & 5 deletions src/simplebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
function SimpleBar (element, options) {
this.el = element,
this.$el = $(element),
this.$scrollContentEl,
this.$contentEl,
this.$track,
this.$scrollbar,
this.dragOffset,
this.flashTimeout,
this.$contentEl = this.$el,
this.$scrollContentEl = this.$el,
this.scrollDirection = 'vert',
this.scrollOffsetAttr = 'scrollTop',
this.sizeAttr = 'height',
Expand Down Expand Up @@ -160,6 +160,10 @@
* Resize scrollbar
*/
SimpleBar.prototype.resizeScrollbar = function () {
if(SCROLLBAR_WIDTH === 0) {
return;
}

var contentSize = this.$contentEl[0][this.scrollSizeAttr],
scrollOffset = this.$scrollContentEl[this.scrollOffsetAttr](), // Either scrollTop() or scrollLeft().
scrollbarSize = this.$track[this.sizeAttr](),
Expand Down Expand Up @@ -237,7 +241,7 @@
SimpleBar.prototype.resizeScrollContent = function () {
if (this.scrollDirection === 'vert'){
this.$scrollContentEl.width(this.$el.width()+SCROLLBAR_WIDTH);
this.$scrollContentEl.height(this.$el.height());
this.$scrollContentEl.height(this.$el.height()+SCROLLBAR_WIDTH);
} else {
this.$scrollContentEl.width(this.$el.width());
this.$scrollContentEl.height(this.$el.height()+SCROLLBAR_WIDTH);
Expand All @@ -258,15 +262,15 @@
* Getter for original scrolling element
*/
SimpleBar.prototype.getScrollElement = function () {
return typeof this.$scrollContentEl === 'undefined' ? this.$el : this.$scrollContentEl;
return this.$scrollContentEl;
};


/**
* Getter for content element
*/
SimpleBar.prototype.getContentElement = function () {
return typeof this.$contentEl === 'undefined' ? this.$el : this.$contentEl;
return this.$contentEl;
};


Expand Down

0 comments on commit b28992f

Please sign in to comment.