I want to implement a scroll function.. So the default of scroll is disabled. And if the user use the scroll button, I want it to be set to the point I want.. How can I implement this function? window.scrollTop is not working.. I tried a lot of different methods but all were not working..
我想实现一个滚动函数..所以滚动的默认值被禁用。如果用户使用滚动按钮,我希望将其设置为我想要的点。我该如何实现此功能? window.scrollTop不工作..我尝试了很多不同的方法,但都没有工作..
$(window).scroll(function() {
$(body).scrollTop = 3000px;
})
2 个解决方案
#1
The scrollTop
property only accepts an integer (not pixels). Omit the px
and it should be fine.
scrollTop属性只接受整数(不是像素)。省略px它应该没问题。
$(window).scroll(function() {
$('body').get(0).scrollTop = 3000; // note that this does only work if body has overflow
// if it hasn't, use window instead
});
#2
There is a plugin for JQuery called ScrollTo that might do exactly what you need.
有一个名为ScrollTo的JQuery插件可能完全符合您的需求。
Check it out here: http://plugins.jquery.com/project/ScrollTo
请在此处查看:http://plugins.jquery.com/project/ScrollTo
#1
The scrollTop
property only accepts an integer (not pixels). Omit the px
and it should be fine.
scrollTop属性只接受整数(不是像素)。省略px它应该没问题。
$(window).scroll(function() {
$('body').get(0).scrollTop = 3000; // note that this does only work if body has overflow
// if it hasn't, use window instead
});
#2
There is a plugin for JQuery called ScrollTo that might do exactly what you need.
有一个名为ScrollTo的JQuery插件可能完全符合您的需求。
Check it out here: http://plugins.jquery.com/project/ScrollTo
请在此处查看:http://plugins.jquery.com/project/ScrollTo