Skip to content

Commit b28992f

Browse files
author
Adrien Grsmto
committed
Fix a bug when scrollbar width is 0 (no mouse plugged or mobile usage)
1 parent 23449c6 commit b28992f

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

demo/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ <h2>Horizontal scroller</h2>
5757
<a class="btn add-more-horiz" href="#">Add content</a>
5858
<a class="btn toggle-width" href="#">Toggle width</a>
5959
</div>
60+
<div style="clear:both;"></div>
6061

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

65-
<script src="../dist/simplebar.min.js"></script>
66+
<script src="../src/simplebar.js"></script>
6667

6768
<script>
6869
$(document).ready(function() {
@@ -72,7 +73,7 @@ <h2>Horizontal scroller</h2>
7273
// Demonstration of changing the vertical scroller content and dimensions.
7374
$('.add-more').on('click', function(e){
7475
e.preventDefault();
75-
$('.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>');
76+
$('.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>');
7677
$('.demo1').simplebar('recalculate');
7778
});
7879
$('.toggle-height').on('click', function(e){
@@ -87,7 +88,7 @@ <h2>Horizontal scroller</h2>
8788
// Demonstration of changing the horizontal scroller content and dimensions.
8889
$('.add-more-horiz').on('click', function(e){
8990
e.preventDefault();
90-
$('.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>');
91+
$('.demo2').simplebar('getContentElement').append('<div class="box">A</div><div class="box">B</div><div class="box">C</div><div class="box">D</div>');
9192
$('.demo2').simplebar('recalculate');
9293
});
9394
$('.toggle-width').on('click', function(e){

dist/simplebar.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SimpleBar.js - v1.1.1
2+
* SimpleBar.js - v1.1.3
33
* Scrollbars, simpler.
44
* https://grsmto.github.io/simplebar/
55
*

dist/simplebar.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"url" : "http://github.com/grsmto/simplebar.git"
99
},
1010
"homepage": "https://grsmto.github.io/simplebar/",
11-
"version": "1.1.2",
11+
"version": "1.1.3",
1212
"devDependencies": {
1313
"grunt": "~0.4.5",
1414
"grunt-cli": "~0.1.13",

src/simplebar.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
function SimpleBar (element, options) {
3535
this.el = element,
3636
this.$el = $(element),
37-
this.$scrollContentEl,
38-
this.$contentEl,
3937
this.$track,
4038
this.$scrollbar,
4139
this.dragOffset,
4240
this.flashTimeout,
41+
this.$contentEl = this.$el,
42+
this.$scrollContentEl = this.$el,
4343
this.scrollDirection = 'vert',
4444
this.scrollOffsetAttr = 'scrollTop',
4545
this.sizeAttr = 'height',
@@ -160,6 +160,10 @@
160160
* Resize scrollbar
161161
*/
162162
SimpleBar.prototype.resizeScrollbar = function () {
163+
if(SCROLLBAR_WIDTH === 0) {
164+
return;
165+
}
166+
163167
var contentSize = this.$contentEl[0][this.scrollSizeAttr],
164168
scrollOffset = this.$scrollContentEl[this.scrollOffsetAttr](), // Either scrollTop() or scrollLeft().
165169
scrollbarSize = this.$track[this.sizeAttr](),
@@ -237,7 +241,7 @@
237241
SimpleBar.prototype.resizeScrollContent = function () {
238242
if (this.scrollDirection === 'vert'){
239243
this.$scrollContentEl.width(this.$el.width()+SCROLLBAR_WIDTH);
240-
this.$scrollContentEl.height(this.$el.height());
244+
this.$scrollContentEl.height(this.$el.height()+SCROLLBAR_WIDTH);
241245
} else {
242246
this.$scrollContentEl.width(this.$el.width());
243247
this.$scrollContentEl.height(this.$el.height()+SCROLLBAR_WIDTH);
@@ -258,15 +262,15 @@
258262
* Getter for original scrolling element
259263
*/
260264
SimpleBar.prototype.getScrollElement = function () {
261-
return typeof this.$scrollContentEl === 'undefined' ? this.$el : this.$scrollContentEl;
265+
return this.$scrollContentEl;
262266
};
263267

264268

265269
/**
266270
* Getter for content element
267271
*/
268272
SimpleBar.prototype.getContentElement = function () {
269-
return typeof this.$contentEl === 'undefined' ? this.$el : this.$contentEl;
273+
return this.$contentEl;
270274
};
271275

272276

0 commit comments

Comments
 (0)