Skip to content

Commit bc85f22

Browse files
committed
Modified the code so mouse wheel is released when the scrollbar reaches
top or bottom of the scrollable area to simulate the behaviour of natural HTML elements such as textarea or div with overflow:auto; Updated version number.
1 parent 0e12a32 commit bc85f22

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

slimScroll.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
33
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
44
*
5-
* Version: 0.4.1
5+
* Version: 0.4.3
66
*
77
*/
88
(function($) {
@@ -34,7 +34,7 @@
3434
// do it for every element that matches selector
3535
this.each(function(){
3636

37-
var isOverPanel, isOverBar, isDragg, queueHide, barHeight,
37+
var isOverPanel, isOverBar, isDragg, queueHide, barHeight, percentScroll,
3838
divS = '<div></div>',
3939
minBarHeight = 30,
4040
releaseScroll = false,
@@ -182,16 +182,15 @@
182182
delta = parseInt(bar.css('top')) + y * wheelStep / 100 * bar.outerHeight();
183183

184184
// move bar, make sure it doesn't go out
185-
delta = Math.max(delta, 0);
186185
var maxTop = me.outerHeight() - bar.outerHeight();
187-
delta = Math.min(delta, maxTop);
186+
delta = Math.min(Math.max(delta, 0), maxTop);
188187

189188
// scroll the scrollbar
190189
bar.css({ top: delta + 'px' });
191190
}
192191

193192
// calculate actual scroll amount
194-
var percentScroll = parseInt( bar.css('top') ) / (me.outerHeight() - bar.outerHeight());
193+
percentScroll = parseInt(bar.css('top')) / (me.outerHeight() - bar.outerHeight());
195194
delta = percentScroll * (me[0].scrollHeight - me.outerHeight());
196195

197196
if (isJump)
@@ -209,7 +208,6 @@
209208

210209
// trigger hide when scroll is stopped
211210
hideBar();
212-
213211
}
214212

215213
var attachWheel = function()
@@ -243,7 +241,10 @@
243241
// recalculate bar height
244242
getBarHeight();
245243
clearTimeout(queueHide);
246-
244+
245+
// release wheel when bar reached top or bottom
246+
releaseScroll = percentScroll == ~~ percentScroll;
247+
247248
// show only when required
248249
if(barHeight >= me.outerHeight()) {
249250
//allow window scroll

slimScroll.min.js

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

0 commit comments

Comments
 (0)