Skip to content

Commit

Permalink
Modified the code so mouse wheel is released when the scrollbar reaches
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rochal committed Dec 6, 2011
1 parent 0e12a32 commit bc85f22
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
15 changes: 8 additions & 7 deletions slimScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
* Version: 0.4.1
* Version: 0.4.3
*
*/
(function($) {
Expand Down Expand Up @@ -34,7 +34,7 @@
// do it for every element that matches selector
this.each(function(){

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

// move bar, make sure it doesn't go out
delta = Math.max(delta, 0);
var maxTop = me.outerHeight() - bar.outerHeight();
delta = Math.min(delta, maxTop);
delta = Math.min(Math.max(delta, 0), maxTop);

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

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

if (isJump)
Expand All @@ -209,7 +208,6 @@

// trigger hide when scroll is stopped
hideBar();

}

var attachWheel = function()
Expand Down Expand Up @@ -243,7 +241,10 @@
// recalculate bar height
getBarHeight();
clearTimeout(queueHide);


// release wheel when bar reached top or bottom
releaseScroll = percentScroll == ~~ percentScroll;

// show only when required
if(barHeight >= me.outerHeight()) {
//allow window scroll
Expand Down
10 changes: 8 additions & 2 deletions slimScroll.min.js

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

0 comments on commit bc85f22

Please sign in to comment.