【发布时间】:2013-03-14 11:26:26
【问题描述】:
是否可以在 JavaScript 中使用鼠标滚轮滚动元素时更改滚动条的速度?
【问题讨论】:
标签: javascript scroll scrollbar mousewheel
是否可以在 JavaScript 中使用鼠标滚轮滚动元素时更改滚动条的速度?
【问题讨论】:
标签: javascript scroll scrollbar mousewheel
你可以这样做:
http://jsfiddle.net/V3aaN/2/(编辑:可能导致癫痫发作或癫痫)
CSS:
#smallBox {
height:400px;
overflow-y:scroll;
}
#whee {
height:20000px;
}
HTML:
<div id="smallbox">
<div id="whee"></div>
</div>
JS:
var thing = $('#smallBox');
var extra = 100;
var old = $(thing).scrollTop();
$(thing).scroll(function() {
if ($(thing).scrollTop() < old) {
$(thing).scrollTop($(thing).scrollTop()-extra);
} else if ($(thing).scrollTop() > old) {
$(thing).scrollTop($(thing).scrollTop()+extra);
}
old = $(thing).scrollTop();
});
【讨论】:
#whee 这样的元素的滚动?将window 替换为'#whee' 似乎不起作用:/