gpt4 book ai didi

jquery - Safari 6,它无法正确调整大小(滚动条不会停留在底部)

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

如果您在 Chrome、FF 或 IE(8) 上测试该网站并调整窗口大小(高度),您会看到滚动条随着中间黄色框内的内容动态移动。

我的问题是,在 Safari 中,它无法正确调整大小。 (滚动条不会停留在div的底部)

这是 JSBIN TEST FILE

HTML:

<body>
<div id="message_box">

<div id="header"> Header </div>

<div id="content">

<ul id="msg_list">

<li>Test file</li>
<li>Test file</li>
<li>Test file</li>
<li>Test file</li> <!-- ...and so on -->

</ul>

</div>

<div id="footer"> Footer </div>

</div>
</body>

CSS:

html, body {
height: 100%;
}

#message_box {
width: 500px;
float: left;
}

#header {
width: 500px;
height: 50px;
background-color: #aaa;
text-align: center;
}

#content {
min-height: 150px;
width: 500px;
position: relative;
background-color: #ffa;
border: solid #cdd1d8;
border-width: 2px 0 2px 0;
overflow-y: scroll !important;
overflow-x: hidden;
}

#msg_list {
width: 100%;
position: absolute;
bottom: 100px;
margin-bottom: 50%;
left: 0;
display: block;
height: 1px;
}

#footer {
height: 300px;
padding: 10px;
background-color: #aaa;
text-align: center;
}

jQuery(v1.10.1):

$(document).ready(auto_size);

$(window).on("resize", auto_size);

function auto_size() {

var body_content_msg = $("body").height(),
header_content_msg = $("#header").height(),
footer_content_msg = $("#footer").height(),
newHeight = body_content_msg - header_content_msg - footer_content_msg + "px";

$("#content").css("height", newHeight);
}

$(document).ready(function(){

$("#content").scrollTop($("#content")[0].scrollHeight);

});

谁能解释一下为什么在 Safari 中会发生这种情况以及如何处理这种情况?

更新:

您必须向上/向下调整窗口大小才能看到 "Test file//FIRST MESSAGE//" 在 Safari 中消失。

这是一个Safari 6 bug Test :

... Safari 6 will perform the scroll, but will report an incorrect value after the scroll is performed unless you repeat the call to $scrollElement.scrollTop(). ...

最佳答案

在下面找到可以解决您的问题的答案。

HTML + CSS 保持不变。

JS

$(document).ready(auto_size);

$(window).resize(function () {
auto_size();
$("#content").scrollTop($("#content")[0].scrollHeight);
});



function auto_size() {

var body_content_msg = $("body").height(),
header_content_msg = $("#header").height(),
footer_content_msg = $("#footer").height(),
newHeight = body_content_msg - header_content_msg - footer_content_msg + "px";

$("#content").css("height", newHeight);
}

$(document).ready(function () {

$("#content").scrollTop($("#content")[0].scrollHeight);

});

基本上每次调整窗口大小时都需要再次调用滚动条的函数。

享受 :)

关于jquery - Safari 6,它无法正确调整大小(滚动条不会停留在底部),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18494425/

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