$(document).ready(function () { var pages = ["page-01", "page-02", "page-03", "page-04", "page-05", "page-06", "page-07"]; var tabs = ["tab-01", "tab-02", "tab-03", "tab-04", "tab-05", "tab-06", "tab-07"]; var pageIds = ["", "availability", "residences", "amenities", "neighborhood", "faq", "contact-us"]; var discoverMore = $("#discover-more"); function updateURL(pageIndex) { var newUrl = window.location.href.split('#')[0] + '#' + pageIds[pageIndex]; window.history.replaceState({ path: newUrl }, '', newUrl); } function activatePage(index, scroll = true) { // Rimuove la classe .is-active da tutti i pages for (var j = 0; j < pages.length; j++) { $("#" + pages[j]).removeClass("is-active"); } // Aggiunge la classe .is-active al page corrispondente $("#" + pages[index]).addClass("is-active"); $("#" + tabs[index]).click(); if (index === 0) { window.history.replaceState({}, document.title, window.location.pathname + window.location.search); } else { updateURL(index); } // Aggiunge un breve ritardo prima di eseguire l'animazione di scroll if (scroll) { setTimeout(function() { $('html, body').animate({ scrollTop: discoverMore.offset().top }, 1000); }, 100); // Ritardo di 100ms } } var pageIndex = window.location.hash ? pageIds.indexOf(window.location.hash.substr(1)) : 0; // Aggiunge la classe .is-active all'elemento corrispondente al pageIndex $("#" + pages[pageIndex]).addClass("is-active"); if (pageIndex > 0) { $("#" + pages[pageIndex]).click(); $("#" + tabs[pageIndex]).click(); } else { activatePage(0, false); // Non esegue lo scroll se non c'è hash nell'URL } for (var i = 0; i < pages.length; i++) { $("#" + pages[i]).on("click", function() { var index = pages.indexOf($(this).attr('id')); activatePage(index); }); } // Event listener per #btn-availability // $("#btn-availability").on("click", function() { // activatePage(1); // L'indice di "availability" è 1 // }); });