首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Chatbox包装块单击按钮

Chatbox包装块单击按钮
EN

Stack Overflow用户
提问于 2019-10-01 11:52:25
回答 2查看 471关注 0票数 0

我有一个chatbox显示和隐藏点击按钮。

例如,在chatbox后面有一些带有按钮的页面。

在这个例子中,按钮是不可点击的。

我该怎么解决这个问题?chatbox甚至没有打开,而且按钮也不能点击。

当我的聊天被关闭时,我希望这个按钮是可点击的。

我试过这样做:

代码语言:javascript
复制
.wrap {
    bottom: 1em;
    display: flex;
    flex-direction: column;
    position: fixed;
    right: 1em;
    z-index: -99; //////// doesn't work
 }

怎么会在我的按钮前面?

这里有我的聊天示例,有一个示例按钮。

代码语言:javascript
复制
    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>';
      }
  });
代码语言:javascript
复制
.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;
    }
}
代码语言:javascript
复制
<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 -->

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-10-01 11:57:55

使用display:nonedisplay:block而不是使用opacity应该可以解决这个问题。

问题在于可见性(和透明度),div仍然在按钮上方,阻止事件到达按钮。使用display属性,div将完全从DOM中删除!

代码语言:javascript
复制
    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>';
      }
  });
代码语言:javascript
复制
.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;
display: none;
}
.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;
  display: block;
}
.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;
    }
}
代码语言:javascript
复制
<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 -->

票数 0
EN

Stack Overflow用户

发布于 2019-10-01 12:05:49

缩放函数就是这样做的,因为它保持其位置,即使它的设置为0,它仍然具有完全的宽度和高度。不透明使它只看不见,但仍然占据着这个位置。

如果您想要酷的效果,不要使用css类和jquery .fadeToggle()

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58184256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档