Remover # da url no script
Bom dia pessoal.
Tive que adaptar um menu que, ao clicar, vai para uma parte da home.
Este é o script:
$("a.menu__item").on('click', function(event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();
// Store hash
var hash = this.hash;
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
} // End if
});
Este é o menu:
<header class="codrops-header">
<div class="container-geral">
<div class="logo-box">
<div class="logo"><a href="#"><img src="images/logo_branco.png" alt=""></a></div>
</div>
<nav class="menu menu--adsila">
<a class="menu__item" href="#home">
<span class="menu__item-name">Home</span>
<!-- <span class="menu__item-label">Explore all artists' portfolios</span> -->
</a>
<a class="menu__item" href="#quem-somos">
<span class="menu__item-name">Quem somos</span>
<!-- <span class="menu__item-label">Discover their stories</span> -->
</a>
<a class="menu__item" href="#o-que-fazemos">
<span class="menu__item-name">O que fazemos</span>
<!-- <span class="menu__item-label">View our event calendar</span> -->
</a>
<a class="menu__item" href="#blog">
<span class="menu__item-name">Blog</span>
<!-- <span class="menu__item-label">Read our mission statement</span> -->
</a>
<a class="menu__item" href="#eventos">
<span class="menu__item-name">Eventos</span>
<!-- <span class="menu__item-label">Get to know our eco village</span> -->
</a>
<a class="menu__item" href="#contato">
<span class="menu__item-name">Contato</span>
<!-- <span class="menu__item-label">Get in touch and find us</span> -->
</a>
</nav>
</div>
</header>
E esta é uma das partes:
<section class="bloco_historia" id="quem-somos">Conteúdo</section>
Hoje, ao clicar em "Quem somos", vai para a parte "Quem somos" corretamente, mas na url fica "[http://localhost/projetos/site/#quem-somos](http://localhost/projetos/llene/#quem-somos)".
Se eu tentar mudar o window.location.hash (na parte "// Add hash (#) to URL when done scrolling (default click behavior)"), eu consigo que fique "[http://localhost/projetos/llene/quem-somos](http://localhost/projetos/llene/#quem-somos)" (sem o #), mas dá erro, dizendo que a página não existe.
É possível manter a mecânica, mas tirando o # da url?
Obrigado!Discussão (0)
Carregando comentários...