5
I have the following code
//Menu Mobile
var closeTab = document.getElementById("close-i");
document.querySelector(".user-list").onclick = function() {
document.documentElement.classList.add("menu-ativo")
};
document.documentElement.onclick = function(event){
if (event.target === document.documentElement) {
document.documentElement.classList.remove("menu-ativo");
}
}
closeTab.onclick = function(event){
document.documentElement.classList.remove("menu-ativo");
}
//Menu Desktop
var menuDesk = document.getElementById("menu-desktop");
var optDesk = document.getElementById("opt-desktop");
var deskIcon = document.getElementById("menu-desk-icon");
menuDesk.onclick = function(event){
if (optDesk.style.display == "none") {
deskIcon.classList.remove("fa-chevron-right");
deskIcon.classList.add("fa-chevron-down");
optDesk.style.display = "inline-block";
}
else{
deskIcon.classList.remove("fa-chevron-down");
deskIcon.classList.add("fa-chevron-right");
optDesk.style.display = "none";
}
};
*But it didn’t work
HTML
<div class="header-mobile on-top" id="mobile-header">
<div class="user-holder">
<p class="user-list"><!-- Ícone para abrir o menu --></p>
<nav class="user-opt">
<p id="close-i">
<i class="fa fa-times fa-2x" aria-hidden="true"></i>
</p>
<!-- Imagem mostrada dentro do menu e nome de usuário -->
<figure class="imagem-atual">
<img src="img/perfil.jpg" alt="imagem-usuário">
<figcaption>Murilo Gambôa</figcaption>
</figure>
<!-- Barra de Opções -->
<ul>
<a href="meu-perfil.html"><li class="item-1"><i class="fa fa-cog i-menu" aria-hidden="true"></i><span>Editar perfil</span></li></a>
<a href="ultimos-adicionados.html"><li class="item-2"><i class="fa fa-video-camera i-menu" aria-hidden="true"></i><span>Últimos vídeos</span></li></a>
<a href="http://webmail.impd.org.br/webmail" target="_blank"><li class="item-3"><i class="fa i-church i-menu"></i><span>Eclesiástico</span></li></a>
<a href="ajuda.html"><li class="item-4"><i class="fa fa-question i-menu" aria-hidden="true"></i><span>Ajuda</span></li></a>
<a href="index.html"><li class="item-5"><i class="fa fa-sign-out i-menu" aria-hidden="true"></i><span>Sair</span></li></a>
</ul>
</nav>
<!-- Ícones sociais -->
<ul class="social" id="social-icons">
<li class="is is-1"><a href="" class="is" target="_blank">Facebook</a></li>
<li class="is is-2"><a href="" class="is" target="_blank">Twitter</a></li>
<li class="is is-3"><a href="" class="is" target="_blank">Instagram</a></li>
<li class="is is-4"><a href="" class="is" target="_blank">YouTube</a></li>
</ul>
</div>
</div>
<div class="header-desk on-top" id="desktop-header">
<div class="user-holder">
<!-- Ícones sociais -->
<ul class="social">
<li class="is is-1"><a href="" class="is" target="_blank">Facebook</a></li>
<li class="is is-2"><a href="" class="is" target="_blank">Twitter</a></li>
<li class="is is-3"><a href="" class="is" target="_blank">Instagram</a></li>
<li class="is is-4"><a href="" class="is" target="_blank">YouTube</a></li>
</ul>
<!-- Menu do Usuário -->
<nav class="user-opt-desk" id="menu-desktop">
<figure>
<img src="img/perfil.jpg">
<figcaption >Nome de Usuário da Silva</figcaption>
</figure>
<i class="fa fa-chevron-right" aria-hidden="true" id="menu-desk-icon"></i>
<!-- Barra de Opções -->
<ul id="opt-desktop">
<a href="meu-perfil.html"><li class="item-1"><i class="fa fa-cog i-menu" aria-hidden="true"></i><span>Editar perfil</span></li></a>
<a href="ultimos-adicionados.html"><li class="item-2"><i class="fa fa-video-camera i-menu" aria-hidden="true"></i><span>Últimos vídeos</span></li></a>
<a href="http://webmail.impd.org.br/webmail" target="_blank"><li class="item-3"><i class="fa i-church i-menu"></i><span>Eclesiástico</span></li></a>
<a href="ajuda.html"><li class="item-4"><i class="fa fa-question i-menu" aria-hidden="true"></i><span>Ajuda</span></li></a>
<a href="index.html"><li class="item-5"><i class="fa fa-sign-out i-menu" aria-hidden="true"></i><span>Sair</span></li></a>
</ul>
</nav>
</div>
</div>
It’s not working here, when I click out, it keeps showing the list, and I wanted to first make it work in normal javascript, then go to jquery, I already did in jquery and it worked, only I really wanted to javascript
– Murilo Melo
Well, I don’t have a clear view of how your HTML is laid out on the screen, but I believe you click anywhere other than the
optDesk
it will close/disable thedisplay
ofoptDesk
. Unless theoptDesk
is covering the entire screen.– lenilsondc
in relation to a screen of
1024x800
, theoptDesk
occupies280x560
– Murilo Melo
I was able to simulate normally on this fiddle: https://jsfiddle.net/d18bmaeb/ from a look kindly.
– lenilsondc
A! I found out what was wrong. I copied the previous code
optDesk.style.display("none");
but I did not find it wrong how to assign the value ofdisplay
in the element. Finally, it is right to assign so:optDesk.style.display = 'none';
.– lenilsondc
I tried again, but it did not work, I will post the mobile JS too, it is working, however the desktop does not... :/
– Murilo Melo