jQuery 向下滚动速度慢
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23950450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Slow scroll speed down
提问by David Hakkert
Ok, so I can't find anything about this.
好的,所以我找不到任何关于此的信息。
I know it is horrible to change the scroll speed of a site, but I need to do this for a site which is more a game than a site.
我知道改变网站的滚动速度很糟糕,但我需要为一个更像是游戏而不是网站的网站这样做。
Can someone tell me how to slow down de scrollspeed? Jquery or css?
有人能告诉我如何减慢滚动速度吗?jQuery 还是 css?
EDIT: I want to change the scrollspeed whem people scroll with the mouse wheel.
编辑:我想改变人们用鼠标滚轮滚动的滚动速度。
采纳答案by Amit Soni
回答by PapaSmurf
Look this fiddle: http://jsfiddle.net/promatik/NFk2L/, you can set time and distance!
看看这个小提琴:http: //jsfiddle.net/promatik/NFk2L/,你可以设置时间和距离!
JS code
JS代码
if (window.addEventListener) window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;
function wheel(event) {
var delta = 0;
if (event.wheelDelta) delta = event.wheelDelta / 120;
else if (event.detail) delta = -event.detail / 3;
handle(delta);
if (event.preventDefault) event.preventDefault();
event.returnValue = false;
}
function handle(delta) {
var time = 1000;
var distance = 300;
$('html, body').stop().animate({
scrollTop: $(window).scrollTop() - (distance * delta)
}, time );
}
if (window.addEventListener) window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;
function wheel(event) {
var delta = 0;
if (event.wheelDelta) delta = event.wheelDelta / 120;
else if (event.detail) delta = -event.detail / 3;
handle(delta);
if (event.preventDefault) event.preventDefault();
event.returnValue = false;
}
function handle(delta) {
var time = 1000;
var distance = 300;
$('html, body').stop().animate({
scrollTop: $(window).scrollTop() - (distance * delta)
}, time);
}
#myDiv {
height: 800px;
width: 100px;
background-color: #CCF;
font-family: 'Trebuchet MS';
font-size: 12px;
line-height: 24px;
padding: 5px;
margin: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="myDiv">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
回答by anu g prem
https://github.com/nathco/jQuery.scrollSpeed
https://github.com/nathco/jQuery.scrollSpeed
You can add the value speed in this code
您可以在此代码中添加值速度
回答by Sney
Just go to the windows mouse properties in control panel there you can set the amount of pages to slide through with one scroll.
只需转到控制面板中的 Windows 鼠标属性,您就可以设置滚动浏览的页面数量。