禁用向上滚动经过特定点 [英] disable scrolling up past specific point
问题描述
如何使查看器无法向上滚动向上(过去某个特定点)?
使查看器无法滚动很容易:
body {
overflow:hidden;
}
但禁止向下滚动。
详细说明
我想要的是一些javascript / jquery代码,不允许向上滚动过一个给定的参数,而查看器仍然可以向上滚动然后在到达之前,只有向上滚动,只要它没有向上滚动超过给定的参数
。你可以设置一个物理点并说出一些东西例如:
$(function(){
var scrollPoint = 200;
var scrolledPast = false;
$(window).scroll(function(){
$(window).scrollTop()> scrollPoint?scrolledPast = true:'';
$(window).scrollTop < scrollPoint&& scrolledPast == true?$(window).scrollTop(scrollPoint):'';
})。scroll();
});
虽然禁用滚动功能似乎有点反直觉 - 为什么不只是隐藏页面本身?
How can I make it so that a viewer cannot scroll up (past a specific point)?
Making it so a viewer cannot scroll is easy with:
body{
overflow: hidden;
}
but that disables scrolling down too.
Detailed description
what I want is some javascript/jquery code that will not allow scrolling up past a given parameter, while the viewer can still scroll up and down before that parameter is reached, but after it is reached they can only scroll up as long as it's not scrolling up past the given parameter
I have absolutely no idea how to go about doing this, any ideas?
You could set a physical point and say something like:
$(function() {
var scrollPoint = 200;
var scrolledPast = false;
$(window).scroll(function() {
$(window).scrollTop() > scrollPoint ? scrolledPast = true : '';
$(window).scrollTop() < scrollPoint && scrolledPast == true ? $(window).scrollTop(scrollPoint) : '';
}).scroll();
});
Although the disabling of scrolling seems a bit counter-intuitive-- why not just hide stuff off the page itself?
这篇关于禁用向上滚动经过特定点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!