Good day. There is some code for smooth animation on anchor links. But there is a navigation header, which is located on all other pages of the site. There is an error in my code, because the id value is passed as "index.php # id", but it is necessary that the top variable contains the id value equal to "#id". Please help remove the value of "index.php" in the variable. Without anchor links with "index.php" links from other pages will not work. At once I will make a reservation, I use an insert in php, therefore such crutches. Or leave the main page with your header, and on all pages create your own code for the header))) But I think that you will help to solve it more beautifully. thank
// ΠΏΠ»Π°Π²Π½Π°Ρ ΠΏΡΠΎΠΊΡΡΡΠ½Π° Π΄ΠΎ Π½Π°ΠΆΠ°ΡΠΎΠ³ΠΎ ΠΏΡΠ½ΠΊΡΠ° ΠΌΠ΅Π½Ρ $("nav li").on("click",".nav_a", function (event) { // ΠΈΡΠΊΠ»ΡΡΠ°Π΅ΠΌ ΡΡΠ°Π½Π΄Π°ΡΡΠ½ΡΡ ΡΠ΅Π°ΠΊΡΠΈΡ Π±ΡΠ°ΡΠ·Π΅ΡΠ° event.preventDefault(); // ΠΏΠΎΠ»ΡΡΠ΅ΠΌ ΠΈΠ΄Π΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΎΡ Π±Π»ΠΎΠΊΠ° ΠΈΠ· Π°ΡΡΠΈΠ±ΡΡΠ° href var id = $(this).attr('href'); // Π½Π°Ρ
ΠΎΠ΄ΠΈΠΌ Π²ΡΡΠΎΡΡ, Π½Π° ΠΊΠΎΡΠΎΡΠΎΠΉ ΡΠ°ΡΠΏΠΎΠ»ΠΎΠΆΠ΅Π½ Π±Π»ΠΎΠΊ console.log(id); var top = $(id).offset().top-60; // Π°Π½ΠΈΠΌΠΈΡΡΠ΅ΠΌ ΠΏΠ΅ΡΠ΅Ρ
ΠΎΠ΄ ΠΊ Π±Π»ΠΎΠΊΡ, Π²ΡΠ΅ΠΌΡ: 800 ΠΌΡ $('body,html').animate({scrollTop: top}, 800); });
var id = "#" + $(this).attr('href').split("#")[1];- Igor