Jquery alterar local e depois rolar para o elemento
Quando estou no index.php e pressiono o botão home, ele rola para baixo até o elemento No entanto, quando não estou no index.php e pressiono o mesmo botão, desejo alterar o local da URL e, em seguida, role até o elemento Foi assim que tentei:
$('.home').on('click', function (event) {
// If location is index.php do this:
if (location.href.indexOf("/index.php") > -1) {
$('html, body').animate({
scrollTop: $("#anotherelement").offset().top
}, 1000);
// If location is not index.php do this:
} else {
window.location = "index.php";
$('html, body').animate({
scrollTop: $("#anotherelement").offset().top
}, 1000);
}
});
Apenas altera o URL, mas não rola para o elemento quando não estou no index.php