gpt4 book ai didi

javascript - 在 css 中聊天的全屏模式

转载 作者:行者123 更新时间:2023-11-28 02:32:51 24 4
gpt4 key购买 nike

我从这个链接 https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_modal2 下载了这个模态弹出脚本

我想用它来构建一个能够响应所有移动设备的模态弹出式聊天。我已将聊天标题设置为 10%,聊天页脚设置为 15%。

请问我该如何:

1.) 设置聊天正文以确保聊天消息在消息超出正文时不会下推模态页脚可能会在正文中添加滚动条,因为剩余高度百分比为 75

2.)它将在移动设备上响应谢谢

下面是我做的

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {font-family: Arial, Helvetica, sans-serif;}

/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
border: 1px solid #888;
width: 80%;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4s
}

/* Add Animation */
@-webkit-keyframes animatetop {
from {top:-300px; opacity:0}
to {top:0; opacity:1}
}

@keyframes animatetop {
from {top:-300px; opacity:0}
to {top:0; opacity:1}
}

/* The Close Button */
.close {
color: white;
float: right;
font-size: 28px;
font-weight: bold;
}

.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}

.modal-header {
padding: 2px 16px;
background-color: #5cb85c;
color: white;
height:10%;
}

.modal-body {padding: 2px 16px;}

.modal-footer {
padding: 2px 16px;
background-color: #5cb85c;
color: white;
postion:fixed;
height:15%;
}
</style>
</head>
<body>

<h2>Animated Modal with Header and Footer</h2>

<!-- Trigger/Open The Modal -->
<button id="myBtn">Open Modal</button>

<!-- The Modal -->
<div id="myModal" class="modal">

<!-- Modal content -->
<div style="width:100%;height:100vh;margin-top:-100px" class="modal-content">
<div class="modal-header">
<span class="close">&times;</span>
<h2>Modal Header</h2>
</div>
<div class="modal-body">
<p>chat messages goes here</p><br>
<p>chat messages goes here</p>
<br><br><br><br><br><br><br><br><br>
<p>chat messages goes here</p>
<p>chat messages goes here</p>
<br><br><br><br><br><br><br>
</div>
<div style="" class="modal-footer">
Chat: <input type="text" placeholder="Chat Message" class="form-control">
<div>Files Goes Here</div>
</div>
</div>

</div>

<script>
// Get the modal
var modal = document.getElementById('myModal');

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>

</body>
</html>

最佳答案

您可以设置模态主体的最大高度,这样它就不会插入页脚并添加自动溢出,这样您就可以仅在需要时在模态主体中滚动。

CSS

.modal-body {
padding: 2px 16px;
max-height: 75%; /* 10% header and 15% from footer */
overflow: auto;
}

关于javascript - 在 css 中聊天的全屏模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49526146/

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