1
I’m trying to add a Transition in a div where I add a class according to the scroll, but it’s not working. Could someone try to help me understand why?
window.addEventListener('scroll', function(){
var pageScrollY = window.scrollY
var msgChat = document.querySelector('.container-msg-chat');
if(pageScrollY >= 1000){
msgChat.classList.add('msg-open');
}else if(msgChat.classList.contains('msg-open')){
msgChat.classList.remove('msg-open');
}
});
a.container-icone--chat{
position: fixed;
bottom: 21px;
right: 21px;
background-color: #f96720;
background-image: url('images/home/chat/icon-chat.png');
background-position-x: 13px;
background-position-y: center;
background-repeat: no-repeat;
width: 64px;
height: 64px;
border-radius: 50%;
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.4);
transition: background-color 1s ease;
}
a.container-icone--chat:hover{
background-color: #fff;
background-position-x: -49px;
}
a.container-msg-chat{
position: fixed;
bottom: 100px;
background-color: #fff;
right: 21px;
width: 125px;
padding: 15px;
text-align: center;
border-radius: 10px;
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.4);
display: none;
transition: all 5s ease;
}
a.container-msg-chat:before{
content: '';
display: inline-block;
position: absolute;
bottom: -9px;
right: 27px;
border-top: 5px solid #fff;
border-right: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 5px solid transparent;
}
.btn-chat{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-indent: -9999px;
}
a.container-msg-chat.msg-open{
display: block!important;
}
.container{
height: 5000px;
}
<div class="container"></div>
<a href="#" class="container-msg-chat">¿Necesita ayuda?</a>
<a href="#" class="container-icone--chat">
<span class="btn-chat">Chat</span>
</a>
Your question is not very clear Filype!
– LeAndrade
Hi @Leandrade, all right? I’m trying to put a Transition in the container-msg-chat, but it’s not happening when I add the msg-open class via js.
– Filype Ferreira