Código JS para colar no Widget HTML
<script>
const controle = document.querySelector("#controle");
const menuLateral = document.getElementById("menuLateral");
const menuMobile = document.querySelector(".menuMobile");
const secoes = document.querySelectorAll(".secao");
const itensLista = document.querySelectorAll(".listaNav a");
console.log(itensLista)
controle.onclick = () => {
menuLateral.classList.toggle("ativo");
};
if (window.innerWidth < 767) {
menuLateral.classList.remove("ativo");
document.addEventListener("click", (event)=>{
let widthMenu = menuLateral.contains(event.target);
let widthBotaoMenu = menuMobile.contains(event.target);
if(!widthMenu && !widthBotaoMenu){
menuLateral.classList.remove("mobile")
}
})
}
menuMobile.onclick = () => {
menuLateral.classList.toggle("mobile");
};
let observar = new IntersectionObserver(aparecerSecao, {threshold: .3});
function aparecerSecao(listaSecoes, observar){
listaSecoes.forEach(secao => {
if(secao.isIntersecting){
itensLista.forEach(itemLista => itemLista.classList.remove("ativo"));
let itemAtivo = document.querySelector(`a[href="#${secao.target.id}"]`);
console.log(itemAtivo)
itemAtivo.classList.add("ativo")
}
});
}
secoes.forEach(secao => {
observar.observe(secao);
})
</script>
Código CSS
#menuLateral{
width: 240px;
background-color: #dedede;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
padding: 60px 20px;
height: 100vh;
position: fixed;
transition: all .5s;
transition-delay: 0s;
}
.perfil{
align-items: center;
justify-content: center;
}
.perfil img{
transition: all .3s;
}
.listaNav{
width: 100%;
}
.listaNav a{
display: flex;
gap: 12px;
padding: 12px 20px !important;
border-radius: 12px;
cursor: pointer;
transition: all .3s;
color: white !important
}
.listaNav a.ativo{
background-color: rgb(98, 0, 255) !important;
}
a.ativo .elementor-icon-list-icon svg, a.ativo .elementor-icon-list-text{
color: white !important;
fill: white !important
}
.listaNav a:hover:not(a.ativo) {
background-color: rgba(98, 0, 255, 0.137);
}
.botaoPrincipal{
transition: all .3s;
border-radius: 12px
}
.botaoPrincipal:hover{
transform: translateY(-2px);
box-shadow: 4px 4px 8px rgba(255, 255, 255, 0.267) inset, -4px -4px 8px rgba(255, 255, 255, 0.267) inset, 0px 8px 12px rgba(33, 32, 34, 0.267);
}
#controle{
position: absolute;
top: 180px;
right: -12px;
transition: all .3s;
cursor: pointer
}
#menuLateral .elementor-icon-list-text, #menuLateral .nomeUsuario{
transition: opacity .3s;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
transition-delay: .2s;
opacity: 1;
}
#menuLateral.ativo li{
gap: 0px;
}
#menuLateral.ativo .textoNav, #menuLateral.ativo .nomeUsuario{
opacity: 0;
width: 0px;
}
#menuLateral.ativo .botaoPrincipal{
width: 0px;
opacity: 0;
overflow: hidden;
}
#menuLateral.ativo{
width: 80px;
padding: 60px 12px;
transition-delay: .1s;
}
#menuLateral.ativo .perfil img{
width: 52px;
}
#menuLateral.ativo #controle{
transform: scaleX(-1);
}
header{
display: none;
}
@media (max-width:767px){
#menuLateral{
transform:translateX(-100%);
padding: 32px 16px;
justify-content: center;
gap: 40px;
}
nav ul{
padding-bottom: 0px;
gap: 20px;
}
#controle{
display: none;
}
#menuLateral.mobile{
transform:translateX(0%);
}
header{
width: 100%;
display: flex;
justify-content: end;
padding: 20px;
}
.menuMobile{
font-size: 30px;
cursor: pointer;
}
}