andbeyond提出了一个很好的解决方案,尽管它与 IE 有问题,所以我试图修复它们,你去:
function stopEvent(e) {
e = e ? e : window.event;
if (e.stopPropagation) e.stopPropagation();
if (e.preventDefault) e.preventDefault();
e.cancelBubble = true;
e.cancel = true;
e.returnValue = false;
return false;
}
$.fn.extend({
// param: (boolean) onlyWhenScrollbarVisible
// If set to true, target container will not intercept mouse wheel
// event if it doesn't have its own scrollbar, i.e. if there is too
// few content in it. I prefer to use it, because if user don't see
// any scrollable content on a page, he don't expect mouse wheel to
// stop working somewhere.
scrollStop: function(onlyWhenScrollbarVisible) {
return this.each(function(){
$(this).on('mousewheel DOMMouseScroll', function(e) {
if (onlyWhenScrollbarVisible && this.scrollHeight <= this.offsetHeight)
return;
e = e.originalEvent;
var delta = (e.wheelDelta) ? -e.wheelDelta : e.detail;
var isIE = Math.abs(delta) >= 120;
var scrollPending = isIE ? delta / 2 : 0;
if (delta < 0 && (this.scrollTop + scrollPending) <= 0) {
this.scrollTop = 0;
stopEvent(e);
}
else if (delta > 0 && (this.scrollTop + scrollPending >= (this.scrollHeight - this.offsetHeight))) {
this.scrollTop = this.scrollHeight - this.offsetHeight;
stopEvent(e);
}
});
});
}
});
现在它完全符合我的要求。感谢andbeyond的精彩博文 - http://www.andbeyonddesign.com/Blog/2012/02/Setting-scroll-only-for-scrollable-div
示例用法:$('.folderlist').scrollStop(true);