添加样式 HTML JS

huangapple go评论52阅读模式
英文:

adding style html js

问题

看我的下面的截图。 如果我删除这个属性,聊天框将不会打开。 我尝试使用CSS删除它,然后使用jquery/js将其添加回来,但不起作用。 如何解决这个问题? 使"div"在关闭格式之前不会覆盖我的背景。

enter image description here

我希望在它打开之前它是关闭的。

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->
function chatInit(selector) {
  document.addEventListener('DOMContentLoaded', () => {
    if (!window.LIVE_CHAT_UI) {
      let chat = document.querySelector(selector);
      let toggles = chat.querySelectorAll('.toggle')
      let close = chat.querySelector('.close')

      toggles.forEach( toggle => {
        toggle.addEventListener('click', () => {
          chat.classList.add('is-active')
        })
      })
      close.addEventListener('click', () => {
        chat.classList.remove('is-active')
      })    

      window.LIVE_CHAT_UI = true
    }
  })
}

chatInit('#chat-app')

<!-- language: lang-css -->
/* 这里是CSS部分,暂不提供翻译 */

<!-- language: lang-html -->
<!-- 这里是HTML部分,暂不提供翻译 -->

<!-- end snippet -->

希望这对你有帮助。如果有任何其他问题,请随时告诉我。

英文:

Look at my screenshot below. If I remove this property the chat will not open. I tried with CSS to remove it and then use jquery/js to add it back, but it doesn't work. How can I solve this problem? That the "div" in closed format would not cover my background

enter image description here

I want it to be closed before it opens<br>

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

function chatInit(selector) {
  document.addEventListener(&#39;DOMContentLoaded&#39;, () =&gt; {
    if (!window.LIVE_CHAT_UI) {
      let chat = document.querySelector(selector);
      let toggles = chat.querySelectorAll(&#39;.toggle&#39;)
      let close = chat.querySelector(&#39;.close&#39;)
      
      toggles.forEach( toggle =&gt; {
        toggle.addEventListener(&#39;click&#39;, () =&gt; {
          chat.classList.add(&#39;is-active&#39;)
        })
      })
      close.addEventListener(&#39;click&#39;, () =&gt; {
        chat.classList.remove(&#39;is-active&#39;)
      })    
      
      window.LIVE_CHAT_UI = true
    }
  })
}

chatInit(&#39;#chat-app&#39;)

<!-- language: lang-css -->

*,
*:after,
*:before {
box-sizing: border-box;
}
.chat-app {
font-size: 18px;
line-height: 1.25;
font-family: &quot;Roboto&quot;, sans-serif;
height: 600px;
width: 360px;
position: fixed;
bottom: 32px;
right: 32px;
color: #141E30;
}
.chat-app .title {
font-size: 1.25em;
font-family: &quot;Raleway&quot;, sans-serif;
font-weight: 600;
margin: 0;
}
.chat-app .subtitle {
font-size: 1em;
font-family: &quot;Raleway&quot;, sans-serif;
font-weight: 500;
margin: 0;
}
.chat-app:not(.is-active) .chat-app_toggle:hover {
-webkit-animation: 0.5s blob linear;
animation: 0.5s blob linear;
}
.chat-app_toggle {
z-index: 5;
position: absolute;
bottom: 0.75em;
right: 0.75em;
height: 64px;
width: 64px;
transform: scale(0.83);
background: linear-gradient(to right, #00c6ff, #0072ff);
border-radius: 100%;
transition: all 0.3s;
box-shadow: 0 10px 20px rgba(0, 198, 255, 0.4);
}
.chat-app_toggle:hover {
cursor: pointer;
transform: none;
}
.chat-app_toggle .icon {
z-index: 2;
color: white;
font-size: 1.5em;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
transition: all cubic-bezier(0.72, 0.17, 0.36, 1.03) 0.4s;
}
.chat-app_toggle:before {
content: &quot;&quot;;
display: block;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: -1;
border-radius: 100%;
border: 2px solid #00c6ff;
opacity: 0;
}
.chat-app_toggle:after {
content: &quot;&quot;;
display: block;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
background: linear-gradient(to right, #00cdac, #00ae92);
border-radius: 100%;
transition: all 0.3s;
opacity: 0;
}
.chat-app_box {
border-radius: 16px 16px 40px 16px;
overflow: hidden;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
position: relative;
height: 600px;
display: flex;
flex-direction: column;
background: white;
}
.chat-app_header {
background: linear-gradient(to right, #00c6ff, #0072ff);
color: white;
position: relative;
}
.chat-app_header .branding {
display: flex;
flex-wrap: wrap;
align-items: center;
padding: 1.5em 1.5em;
}
.chat-app_header .close {
height: 1.5em;
width: 1.5em;
background: #141e30;
position: absolute;
top: 1em;
right: 1em;
border-radius: 100%;
z-index: 2;
transition: all 0.3s;
opacity: 0.5;
}
.chat-app_header .close:after, .chat-app_header .close:before {
content: &quot;&quot;;
height: 2px;
width: 1em;
position: absolute;
left: 0.25em;
top: calc(50% - 1px);
background: white;
transform: rotate(45deg);
}
.chat-app_header .close:before {
transform: rotate(-45deg);
}
.chat-app_header .close:hover {
cursor: pointer;
transform: scale(1.2);
opacity: 1;
}
.chat-app_header .avatar {
margin-right: 1em;
position: relative;
width: 48px;
height: 48px;
}
.chat-app_header .avatar img {
width: 48px;
height: 48px;
-o-object-fit: cover;
object-fit: cover;
border-radius: 100%;
box-shadow: 0 5px 10px rgba(20, 30, 48, 0.2);
}
.chat-app_header .avatar.is-online:after {
content: &quot;&quot;;
display: block;
height: 0.75em;
width: 0.75em;
position: absolute;
bottom: 0.2em;
right: 0.2em;
background: #00cdac;
z-index: 2;
border-radius: 100%;
box-shadow: 0 0 0 2px white;
}
.chat-app_header .content {
width: calc(100% - 48px - 1em);
}
.chat-app_content {
height: 100%;
width: calc(100% - 1em);
position: relative;
bottom: 0;
left: 0;
right: 0;
overflow: auto;
margin: 0 0.5em;
}
.chat-app_content::-webkit-scrollbar {
width: 0.5em;
background-color: transparent;
}
.chat-app_content::-webkit-scrollbar-thumb {
border-radius: 10px;
background-color: #ededed;
}
.chat-app_content .messages {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
overflow: auto;
padding: 0 1em;
position: absolute;
padding-bottom: 1em;
width: 100%;
}
.chat-app_content .message {
width: calc(100% - 2em);
padding: 0 0.75em 0 0.75em; /* Haut droite bas gauche */
background: white;
margin-top: 0.25em;
border-radius: 16px;
margin-left: 2em;
background: linear-gradient(to right, #00c6ff, #0072ff);
color: white;
position: relative;
opacity: 1;
transform: scale(0.8);
transform-origin: 100% 100%;
word-break: break-word;;
}
.chat-app_content .message:after {
content: &quot;&quot;;
display: block;
height: 1em;
width: 1em;
position: absolute;
bottom: 0.75em;
right: -1em;
-webkit-clip-path: polygon(0 0, 0% 100%, 75% 100%);
clip-path: polygon(0 0, 0% 100%, 75% 100%);
background: #0072ff;
transform: skewY(15deg);
}
.chat-app_content .message.reply {
margin-left: 0;
margin-right: 2em;
background: #ededed;
color: #141E30;
transform-origin: 0 100%;
}
.chat-app_content .message.reply:after {
right: unset;
left: -1em;
-webkit-clip-path: polygon(100% 0, 25% 100%, 100% 100%);
clip-path: polygon(100% 0, 25% 100%, 100% 100%);
background: #ededed;
transform: skewY(-15deg);
}
.chat-app_footer {
background: white;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
padding: 1.5em;
padding-top: 0.75em;
position: relative;
}
.chat-app_footer .tools {
display: flex;
margin-bottom: 0.75em;
}
.chat-app_footer .tools .copyright {
margin-left: auto;
display: block;
color: #a0a0a0;
font-size: 0.75em;
letter-spacing: 0.1em;
text-transform: uppercase;
padding: 0.5em 1.5em;
text-align: right;
display: flex;
align-items: center;
justify-content: right;
}
.chat-app_footer .tools .button-icon {
margin-right: 0.25em;
background: white;
width: 2em;
height: 2em;
display: flex;
align-items: center;
justify-content: center;
border-radius: 100%;
transition: all 0.3s;
color: #a0a0a0;
position: relative;
}
.chat-app_footer .tools .button-icon i {
position: relative;
z-index: 2;
}
.chat-app_footer .tools .button-icon:after {
display: block;
content: &quot;&quot;;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: linear-gradient(to right, #00c6ff, #0072ff);
z-index: 1;
opacity: 0;
transition: all 0.3s;
border-radius: 100%;
}
.chat-app_footer .tools .button-icon:hover, .chat-app_footer .tools .button-icon:focus {
cursor: pointer;
box-shadow: 0 5px 10px rgba(0, 198, 255, 0.4);
color: white;
transform: scale(1.1);
}
.chat-app_footer .tools .button-icon:hover:after, .chat-app_footer .tools .button-icon:focus:after {
opacity: 1;
}
.chat-input {
height: 2.5em;
width: 100%;
border: none;
background: #ededed;
border: solid 1px #a0a0a0;
border-radius: 1000px;
padding: 1em 1em;
font-size: 1em;
transition: all 0.3s;
}
.chat-input:focus {
outline: none;
box-shadow: 0 10px 20px rgba(0, 205, 172, 0.4);
border-color: #00cdac;
background: white;
}
.chat-app .chat-app_box {
transition: all cubic-bezier(0.71, 0, 0.23, 1.38) 0.5s;
opacity: 0;
visibility: hidden;
pointer-events: none;
transform-origin: 100% 100%;
transform: rotate(-3deg) scale(0.8);
}
.chat-app .chat-app_header .avatar {
transition: all 0.4s;
opacity: 0;
transform: scale(0.6);
transition-delay: 0.2s;
}
.chat-app .chat-app_header .content {
transition: all 0.4s;
opacity: 0;
transform: scale(0.9);
transition-delay: 0.3s;
}
.chat-app .icon.send {
opacity: 0;
transform: translateY(-100%) scale(0.5);
}
.chat-app .icon.open {
opacity: 1;
transform: translateY(0);
}
.chat-app .chat-input {
transition: all 0.4s;
opacity: 0;
}
.chat-app.is-active .chat-app_box {
opacity: 1;
visibility: visible;
pointer-events: unset;
transform: none;
}
.chat-app.is-active .chat-app_header .avatar,
.chat-app.is-active .chat-app_header .content {
opacity: 1;
transform: none;
}
.chat-app.is-active .icon.send {
opacity: 1;
transform: translateY(0);
}
.chat-app.is-active .icon.open {
opacity: 0;
transform: translateY(100%) scale(0.5);
}
.chat-app.is-active .chat-app_toggle:before {
-webkit-animation: chat-bubble cubic-bezier(0.15, 0.4, 0.15, 1) 0.7s;
animation: chat-bubble cubic-bezier(0.15, 0.4, 0.15, 1) 0.7s;
}
.chat-app.is-active .chat-app_toggle:after {
opacity: 1;
}
.chat-app.is-active .chat-input {
opacity: 1;
}
@media screen and (max-width: 700px) {
.chat-app .chat-app_box {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 0;
}
.chat-app .chat-app_toggle {
position: fixed;
bottom: 0.75em;
right: 0.75em;
}
}
@-webkit-keyframes chat-bubble {
0% {
opacity: 0;
transform: scale(0.7);
}
25% {
opacity: 1;
}
100% {
opacity: 0;
transform: scale(1.6);
}
}
@keyframes chat-bubble {
0% {
opacity: 0;
transform: scale(0.7);
}
25% {
opacity: 1;
}
100% {
opacity: 0;
transform: scale(1.6);
}
}
@-webkit-keyframes blob {
0% {
border-radius: 100% 100% 100% 100%;
}
25% {
border-radius: 60% 95% 60% 95%;
}
50% {
border-radius: 90% 65% 90% 65%;
}
75% {
border-radius: 80% 98% 80% 98%;
}
100% {
border-radius: 100% 100% 100% 100%;
}
}
@keyframes blob {
0% {
border-radius: 100% 100% 100% 100%;
}
25% {
border-radius: 60% 95% 60% 95%;
}
50% {
border-radius: 90% 65% 90% 65%;
}
75% {
border-radius: 80% 98% 80% 98%;
}
100% {
border-radius: 100% 100% 100% 100%;
}
}

<!-- language: lang-html -->

&lt;link href=&quot;https://fonts.googleapis.com/css?family=Raleway:500:600|Roboto&amp;display=swap&quot; rel=&quot;stylesheet&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.2/css/all.css&quot;&gt;
&lt;div id=&quot;chat-app&quot; class=&quot;chat-app&quot;&gt;
&lt;div class=&quot;chat-app_toggle toggle&quot;&gt;
&lt;div class=&quot;icon send&quot;&gt;
&lt;i class=&quot;fas fa-paper-plane&quot;&gt;&lt;/i&gt;
&lt;/div&gt;
&lt;div class=&quot;icon open&quot;&gt;
&lt;i class=&quot;fas fa-comment&quot;&gt;&lt;/i&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;chat-app_box&quot;&gt;
&lt;div class=&quot;chat-app_header&quot;&gt;
&lt;div class=&quot;close&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;p class=&quot;title&quot;&gt;ChatBot&lt;/p&gt;
&lt;p class=&quot;subtitle&quot;&gt;Ask me anything, I am here to help you.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

答案1

得分: 0

尝试将以下内容添加到您的CSS代码中

div#chat-app { height: 0; }
div#chat-app.is-active { height: 600px; }
英文:

try adding this to your css code

div#chat-app { height: 0; }
div#chat-app.is-active { height: 600px; } 

huangapple
  • 本文由 发表于 2023年2月27日 10:24:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75576302.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定