Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa tarde!
Montei um site no estilo One page, e a url fica: http://site.com.br/#inicio ou http://site.com.br/#pagina2 ou http://site.com.br/#pagina3
conforme navega-se nele. Gostaria de tornar a url mais amigável, mostrando somente http://site.com.br/inicio ou http://site.com.br/pagina2
ou seja, removendo a hash.
Tentei com o htaccess mod rewrite, dessa forma:
RewriteEngine on
RewriteRule ^http://site.com.br/#inicio$ http://site.com.br/inicio
Mas não deu certo, continua igual. Será que a melhor forma de resolver é pelo mod_rewrite ou pelo JS do one_page? Abaixo vai o JS utilizado:
$(document).ready(function () {
$(document).on("scroll", onScroll);
//smoothscroll
$('a[href^="#"]').on('click', function (e) {
e.preventDefault();
$(document).off("scroll");
$('a').each(function () {
$(this).removeClass('active');
})
$(this).addClass('active');
var target = this.hash,
menu = target;
$target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top+2
}, 500, 'swing', function () {
window.location.hash = target;
$(document).on("scroll", onScroll);
});
});
});
function onScroll(event){
var scrollPos = $(document).scrollTop();
$('#menu-center a').each(function () {
var currLink = $(this);
var refElement = $(currLink.attr("href"));
if (refElement.position().top <= scrollPos && refElement.position().top + refElement.height() > scrollPos) {
$('#menu-center ul li a').removeClass("active");
currLink.addClass("active");
}
else{
currLink.removeClass("active");
}
});
}
Alguém sabe como resolver utilizando o mod_rewrite ou adaptando esse JS??????Carregando comentários...