Smooth scrolling should only be on the main page, and all other transitions should be standard.

I use such a smooth transition, but it only works on the main page:

jQuery(document).ready(function($){ $('#primary-menu li a').click( function(){ // Π»ΠΎΠ²ΠΈΠΌ ΠΊΠ»ΠΈΠΊ ΠΏΠΎ ссылкС с классом go_to var scroll_el = $(this).attr('href'); // возьмСм содСрТимоС Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Π° href, Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ сСлСктором, Ρ‚.Π΅. Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ Π½Π°Ρ‡ΠΈΠ½Π°Ρ‚ΡŒΡΡ с # ΠΈΠ»ΠΈ . if ($(scroll_el).length != 0) { // ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΠΌ сущСствованиС элСмСнта Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΈΠ·Π±Π΅ΠΆΠ°Ρ‚ΡŒ ошибки $('html, body').animate({ scrollTop: $(scroll_el).offset().top }, 500); // Π°Π½ΠΈΠΌΠΈΡ€ΡƒΠ΅ΠΌ скроолинг ΠΊ элСмСнту scroll_el } // return false; // Π²Ρ‹ΠΊΠ»ΡŽΡ‡Π°Π΅ΠΌ стандартноС дСйствиС }); }); 

    1 answer 1

    Try this:

     jQuery(document).ready(function($) { $('#primary-menu li a').click(function () { // Π»ΠΎΠ²ΠΈΠΌ ΠΊΠ»ΠΈΠΊ ΠΏΠΎ ссылкС с классом go_to if (window.location.href.split('#')[0] != $(this).attr('href').split('#')[0]) return; // Π²Ρ‹ΠΉΡ‚ΠΈ, Ссли Π½Π΅ тСкущая страница var scroll_el = '#' + $(this).attr('href').split('#')[1]; // возьмСм содСрТимоС Π°Ρ‚Ρ€ΠΈΠ±ΡƒΡ‚Π° href, Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ сСлСктором, Ρ‚.Π΅. Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ Π½Π°Ρ‡ΠΈΠ½Π°Ρ‚ΡŒΡΡ с # ΠΈΠ»ΠΈ . if ($(scroll_el).length != 0) { // ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΈΠΌ сущСствованиС элСмСнта Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΈΠ·Π±Π΅ΠΆΠ°Ρ‚ΡŒ ошибки $('html, body').animate({scrollTop: $(scroll_el).offset().top}, 500); // Π°Π½ΠΈΠΌΠΈΡ€ΡƒΠ΅ΠΌ скроолинг ΠΊ элСмСнту scroll_el } // return false; // Π²Ρ‹ΠΊΠ»ΡŽΡ‡Π°Π΅ΠΌ стандартноС дСйствиС }); }); 
    • It does not work, the address bar should be solar / # fifth-block, and it writes solar / feedback / # fifth-block feedback is the page on which I press the menu item - user258149
    • I also tried to use .each () by changing the URL on all pages except home, but I couldn’t manage to do it. I stopped at this var bicackle = $ ('# primary-menu li a'). $ .each ($ ('# primary-menu li a'), function (i, item) {console.log (bicackle + item);}) - user258149
    • the same is only a smooth scroll gone)) - user258149
    • Ehh, so give answers without tests. I usually don't do that. Ok, in the evening I will do a test and fix it. - KAGG Design
    • that's okay, I can always return it as it was) here the main thing is to find a solution, so that it would switch and scroll smoothly - user258149