gpt4 book ai didi

Jquery,浏览器刷新时窗口自动向下滚动

转载 作者:行者123 更新时间:2023-11-28 06:44:11 25 4
gpt4 key购买 nike

我将一个 div 设置为窗口的高度和宽度,因此它看起来像一个“主屏幕”,然后您可以向下滚动以查看内容并且它工作正常,但是当浏览器刷新时它会自动向下滚动到刷新前你所在的位置,但我希望它位于文档的“0”点,知道发生了什么吗?

这是我的代码:

            <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="jquery/jquery-1.11.2.min.js"></script>
</head>

<style>
html,body,p,h1,h2,div,section,img{
margin:0;
padding:0;

}
html,body{
background:rgba(255,255,255,1.00);
}
header{
background-color:rgba(181,255,0,0.51);
width:100%;
/* flex container */
display: flex;
flex-flow: row no-wrap;
justify-content: center;
}
section{
text-align:center;
}

</style>
<body>
<header></header>
<section>
<h2>Text</h2>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing 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."</p>
</section>

</body>
<script>
$(document).ready(function(){
$(window).scroll(function(){
console.log($(window).scrollTop());
});

//screen size
var windowh = $(window).height();
var windoww = $(window).width();
//header full screen
console.log(windowh + ' '+windoww);
$('header').css({
'height': windowh,
});

});





</script>
</html>

最佳答案

我认为这与缓存或 cookie 有关,但我相信这可能会阻止网站这样做...

$(window).on('beforeunload', function(){
$(window).scrollTop(0);
});

关于Jquery,浏览器刷新时窗口自动向下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34127616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com