Enhance scroll preventDefault logic.

Now scroll preventDefault works more like default browser scroll.
When the scroll leaches top, bottom, left and right end, don't
prevent default scrolling. For sure, when the content size is
smaller than the container size, also don't prevent default scrolling.
This commit is contained in:
Hyunje Alex Jun 2013-02-16 00:17:23 +09:00
parent 1cdbc9509f
commit aa213398f3

View File

@ -166,6 +166,25 @@
// bind handlers // bind handlers
var bindMouseWheelHandler = function() { var bindMouseWheelHandler = function() {
var shouldPreventDefault = function(deltaX, deltaY) {
var scrollTop = $this.scrollTop();
if(scrollTop == 0 && deltaY > 0 && deltaX == 0) {
return false;
}
else if(scrollTop >= content_height - container_height && deltaY < 0 && deltaX == 0) {
return false;
}
var scrollLeft = $this.scrollLeft();
if(scrollLeft == 0 && deltaX < 0 && deltaY == 0) {
return false;
}
else if(scrollLeft >= content_width - container_width && deltaX > 0 && deltaY == 0) {
return false;
}
return true;
};
$this.mousewheel(function(e, delta, deltaX, deltaY) { $this.mousewheel(function(e, delta, deltaX, deltaY) {
$this.scrollTop($this.scrollTop() - (deltaY * 10)); $this.scrollTop($this.scrollTop() - (deltaY * 10));
$this.scrollLeft($this.scrollLeft() + (deltaX * 10)); $this.scrollLeft($this.scrollLeft() + (deltaX * 10));
@ -173,7 +192,7 @@
// update bar position // update bar position
updateBarSizeAndPosition(); updateBarSizeAndPosition();
if(content_height > container_height || content_width > container_width) { if(shouldPreventDefault(deltaX, deltaY)) {
e.preventDefault(); e.preventDefault();
} }
}); });