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); }); 
  • one
    var id = "#" + $(this).attr('href').split("#")[1]; - Igor
  • Thank you very much! Your decision helped - Vladimir Tytykalo

0