3

I have problem with next/previous Buttons in Pagination on category listing page.

enter image description here

If user click's on next/previous button, it reloads the page (I think) in Ajax at the current page scroll position. Is there any method to force the reload jump to top of page?

3
  • I'm voting to close this question as off-topic because the question does not belong to Magento (in my opinion). Please explain a bit more if you think that your question is valid for this site. Mar 12, 2019 at 11:03
  • Because why? If have this problem in Magento2 pagination. Why should it be off-topic? Normal JS solutions doesnt work. I think, thats a M2 problem...
    – Marcel
    Mar 12, 2019 at 12:59
  • Could be closed/deleted. Its a fault from an extension.
    – Marcel
    Mar 12, 2019 at 13:38

1 Answer 1

4

You can do it by using jquery, add the following script in phtml file.

<script>
 require(['jquery', 'jquery/ui'], function($){
  $(".class of your nav button").click(function() {
  $("html, body").animate({ scrollTop: 0 }, "slow");
  });
</script>

use your nav button class like $(".nav_btn")

or

you can use following code in success event of ajax

 $("html, body").animate({ scrollTop: 0 }, "slow");

or make a function and call the function on click of the button

 <script>

function movetotop(){
     require(['jquery', 'jquery/ui'], function($){

      $("html, body").animate({ scrollTop: 0 }, "slow");
      }
    </script>

and call this function like <a class ="nav_btn" href="#" onclick="movetotop()" ></a>

write the script outside of the file that is updating on ajax request

3
  • Good answer. +1 Mar 12, 2019 at 10:19
  • I use this (2 pagination at top and bottom), but it only works for the 1st time .require(['jquery', 'jquery/ui'], function($){ $("ul.pages-items a").each(function(index) { $(this).click(function() { $("html, body").animate({ scrollTop: 0 }, "slow"); }); }); });
    – Marcel
    Mar 12, 2019 at 12:45
  • then make a function and write the script in it and call the function on click of the button
    – Waqar
    Mar 13, 2019 at 6:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.