Cambie la ubicación de Jquery luego desplácese al elemento
Cuando estoy en index.php y presiono el botón de inicio, se desplaza hacia abajo hasta el elemento. Sin embargo, cuando no estoy en index.php y presiono el mismo botón, quiero cambiar la ubicación de la URL y luego desplazarme al elemento. Así es como lo intenté:
$('.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);
}
});
Simplemente cambia la url pero no se desplaza al elemento cuando no estoy en el index.php