不允许在窗口调整大小上滚动
是否可以在窗口调整大小时阻止滚动?我有一个网站,由 4 个部分(div)组成,每个部分都占窗口的大小。
HTML
<html>
<body>
<div id="home" class="section"></div>
<div id="works" class="section"></div>
<div id="contact" class="section"></div>
<div id="about" class="section"></div>
</body>
</html>
CSS
.section{
margin: 0;
width:100%;
}
JQUERY
$(document).ready(function() {
$(".section").height($(window).height());
$(".section").css("min-height", "768px");
$(window).resize(function() {
$(".section").height($(window).height());
var bodyheight = $(window).height();
});
});
如您所见,我在上面添加了一段代码,您将在其中看到每个 div 都有窗口的大小,如下所示调整大小的行为,最小高度为 768px,但是每次调整大小时,它都会跳转(滚动)到下一部分,当调整窗口大小时,可以使其停留在当前部分吗?
Is it possible to block scrolling on window resize? I have a website which is compose by 4 sections(divs), each one takes the size of the window.
HTML
<html>
<body>
<div id="home" class="section"></div>
<div id="works" class="section"></div>
<div id="contact" class="section"></div>
<div id="about" class="section"></div>
</body>
</html>
CSS
.section{
margin: 0;
width:100%;
}
JQUERY
$(document).ready(function() {
$(".section").height($(window).height());
$(".section").css("min-height", "768px");
$(window).resize(function() {
$(".section").height($(window).height());
var bodyheight = $(window).height();
});
});
As you can see I'm adding a code above in which you will see each div have the size of the window and follows the behavior of resizing and have 768px as min-height, but every time I resize it, it jumps (scrolls) to the next section, it's possible to make it stay at the current section when window is resized?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 Aurora、Opera 和 Chrome 中测试了它,调整大小时它不会滚动到以前的内容,除非在调整页面大小时向页面添加了动态内容。
例如,我添加
到您的功能中,然后由于附加内容,页面上出现滚动
I tested it in Aurora, Opera and Chrome and it does not scroll to previous content when resized unless there is dynamic content added to the page while the page is resizing.
For instance, I added
to your function and then, due to the additional content, there was scrolling on the page