gpt4 book ai didi

javascript - 粘性或固定覆盖到可滚动 div-JavaScript 的可见区域

转载 作者:行者123 更新时间:2023-11-30 14:21:23 26 4
gpt4 key购买 nike

我有一个聊天框的代码,它在向其中添加消息时滚动。我必须在其上显示一个覆盖层,它不应向上滚动消息,如果滚动聊天框,它应该停留在消息上方,它会在添加消息时滚动到底部。

<style>
#overlay {
display: none;
width:100%;
height: 100%;
background-color: rgba(0,0,0,0.8);
z-index: 2;
cursor: pointer;
position: absolute;
bottom: 0;

}
.chat-area {
background-color:#f3f3f3;
height: 75px;
overflow-y:auto;
position:relative
}
<style>

<div class="chat-area" id="chat-area">
<div id="overlay">
<div class="warning">Registro requerido para chatear
<a href="http://trackstuff.net/path/out.php" target="_blank">Regístrate ahora</a></div>
</div><!-- overlay -->
<div class='row chat-entered'>
<div class='isTyping'><a href="http://trackstuff.net/path/out.php" class="is-typing-link">SexySlut22</a> está escribiendo......</div>
</div>
</div><!-- chat-area -->

在聊天框中添加新消息时,我使用这行 js 使其滚动到底部的最新消息。

let objDiv = document.getElementById("chat-area");
objDiv.scrollTop = objDiv.scrollHeight;

我试过固定位置覆盖它让它消失了..请让我知道是否有 JS 或 CSS 的解决方案。非常感谢

最佳答案

是这样的吗?

setInterval(function(){

let messages = document.getElementById('messages');

messages.innerHTML = messages.innerHTML +
'<div class="row chat-entered">' +
'<div class="isTyping"><a href="#" class="is-typing-link">Username</a>:' + Math.random() + '</div>' +
'</div>';

let objDiv = document.getElementById("messages");
objDiv.scrollTop = objDiv.scrollHeight;

}, 400);
#overlay {
width:100%;
height:100%;
background-color: rgba(0,0,0,0.5);
z-index: 2;
cursor: pointer;
position: absolute;
bottom: 0;
color:white;
}
#overlay a {
color:white;
text-decoration: underline;
}
.warning {
position: absolute;
top:50%; left:0
transform:translate3d(-50%, 0, 0);
text-align:center;
width:100%;
display:block;
}
.chat-area {
display: block;
background-color:#f3f3f3;
position: relative
}
#messages {
overflow:hidden;
height:200px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>

<div class="chat-area" id="chat-area">
<div id="overlay">
<div class="warning">Registro requerido para chatear <a target="_blank">Regístrate ahora</a></div>
</div><!-- overlay -->
<div id="messages">
<div class='row chat-entered'>
<div class='isTyping'><a href="#" class="is-typing-link">Username</a> está escribiendo......</div>
</div>
</div><!-- messages -->
</div><!-- chat-area -->

</body>
</html>

关于javascript - 粘性或固定覆盖到可滚动 div-JavaScript 的可见区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52684375/

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