gpt4 book ai didi

javascript - 聊天框包装器 block 单击按钮

转载 作者:太空宇宙 更新时间:2023-11-04 00:41:42 25 4
gpt4 key购买 nike

我有一个聊天框,可以在点击按钮时显示和隐藏。
例如,我有一些页面在聊天框后面有一些按钮。
在这个例子中,按钮是不可点击的。
我该如何解决?聊天框甚至没有打开,按钮仍然不可点击。
我希望当我的聊天关闭时按钮可以点击。
我试着这样做:

.wrap {
bottom: 1em;
display: flex;
flex-direction: column;
position: fixed;
right: 1em;
z-index: -99; //////// doesn't work
}

它怎么会出现在我的按钮前面?
这里有我的聊天示例和示例按钮。

    const btn = document.querySelector(".js-chat");

const chatBox = document.querySelector(".js-chatbox");
$("#chat-circle").click(function() {
$("#chat-circle").toggle('scale');
$(".chat-box").toggle('scale');
});

$(".chat-box-toggle").click(function() {
$("#chat-circle").toggle('scale');
$(".chat-box").toggle('scale');
});

btn.addEventListener("click", () => {
chatBox.classList.toggle("chatbox--is-visible");

if (chatBox.classList.contains("chatbox--is-visible")) {
btn.innerHTML = '<i class="fa fa-times"></i>';
} else {
btn.innerHTML = '<i class="fa fa-comments"></i>';
}
});
.wrap {
bottom: 1em;
display: flex;
flex-direction: column;
position: fixed;
right: 1em;
}
button{
float: right;
margin-top: 70px;
margin-right: 20px;
}
.btn--chat {
align-self: flex-end;
background: #46A7B3;
box-shadow: 3px 3px 1px rgba(0, 0, 0, 0.15);
color: #fff !important;
display: block;
font-size: 1.8em;
margin-top: 0.5em;
transition: all 300ms ease;
text-align: center;
height: 60px;
width: 60px;
border-radius: 50%;
}
.btn--chat:hover {
background: #37848e;
}
.chatbox {
border-radius: 0.5em;
opacity: 0;
order: -1;
transition: all 300ms ease;
transform-origin: 100% 100%;
transform: scale(0);
visibility: hidden;
width: 300px;
box-shadow: -2px 2px 15px 4px #222d32;
}
.chatbox__input {
border-radius: 0.5em;
border: 0;
color: #555;
font-size: 0.9rem;
padding: 2em 1em;
position: relative;
resize: none;
}
.chatbox__input:required {
box-shadow: none;
}
.chatbox__submit {
background: none;
border: 0;
bottom: 0.75em;
cursor: pointer;
color: #3e54a4;
font-size: 0.85rem;
position: absolute;
right: 0.5em;
}
.chatbox--is-visible {
opacity: 1;
transform: scale(1);
visibility: visible;
}
.chat-box-header {
background: #46A7B3;
height:30px;
border-top-left-radius:5px;
border-top-right-radius:5px;
color:white;
text-align:center;
font-size:20px;
padding-top:17px;
}
.chat-box-body {
position: relative;
height:300px;
height:auto;
border:1px solid #ccc;
overflow: hidden;
}
.chat-box-body:after {
content: "";
background: blue;
opacity: 0.1;
top: 0;
left: 0;
bottom: 0;
right: 0;
height:100%;
position: absolute;
z-index: -1;
}
#chat-input {
background: #f4f7f9;
width:77%;
position:relative;
height:47px;
padding-top:10px;
padding-right:50px;
padding-bottom:10px;
padding-left:15px;
border:none;
resize:none;
outline:none;
border:1px solid #ccc;
color:#888;
border-top:none;
border-bottom-right-radius:5px;
border-bottom-left-radius:5px;
overflow:hidden;
}
.chat-input > form {
margin-bottom: 0;
}
#chat-input::-webkit-input-placeholder { /* Chrome/Opera/Safari */
color: #ccc;
}
#chat-input::-moz-placeholder { /* Firefox 19+ */
color: #ccc;
}
#chat-input:-ms-input-placeholder { /* IE 10+ */
color: #ccc;
}
#chat-input:-moz-placeholder { /* Firefox 18- */
color: #ccc;
}
.chat-submit {
position:absolute;
bottom:5px;
right:10px;
background: transparent;
box-shadow:none;
border:none;
border-radius:50%;
color:#46a7b3;
width:35px;
height:35px;
}
.chat-logs {
padding:15px;
height:170px;
overflow-y:scroll;
background: #939393;
}

.chat-logs::-webkit-scrollbar-track
{
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
background-color: #F5F5F5;
}

.chat-logs::-webkit-scrollbar
{
width: 5px;
background-color: #F5F5F5;
}

.chat-logs::-webkit-scrollbar-thumb
{
background-color: #5A5EB9;
}



@media only screen and (max-width: 500px) {
.chat-logs {
height:20vh;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<button> click me (doesnt work) </button>

<!-- Button trigger modal -->
<div class="wrap">
<button class=" btn btn--chat js-chat"><i class="fa fa-comments"></i></button>
<div class="chatbox js-chatbox">
<div class="chat-box" style="display: block;">
<div class="chat-box-header">
Chat
</div>
<div class="chat-box-body">
<div class="chat-box-overlay">
</div>
<div class="chat-logs">
</div>
</div>
<div class="chat-input">
<input type="text" id="chat-input" placeholder="message" DISABLED AUTOFOCUS>
<button class="chat-submit" id="chat-submit" DISABLED><i class="fa fa-paper-plane"></i></button>
</div>
</div>
<!-- End of .chatbox__form -->
</div>
<!-- End of .chatbox.js-chatbox -->
</div>
<!-- End of .wrapper -->

最佳答案

Scale 函数就是这样做的,因为它保持它的位置,即使它设置为 0 它仍然具有完整的宽度和高度。不透明度使它只是不可见但仍然保持位置。

如果你想要很酷的效果,不要使用 css class 而使用 jquery funcion .fadeToggle() .

关于javascript - 聊天框包装器 block 单击按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58184256/

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