2

I have problem with next/prev Buttons in Pagination. If user clicks 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?

closed as unclear what you're asking by Manashvi Birla, Jai, Mohit Kumar Arora, saravanavelu, PЯINCƏ Mar 12 at 13:52

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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. – Mohit Kumar Arora Mar 12 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 at 12:59
  • Could be closed/deleted. Its a fault from an extension. – Marcel Mar 12 at 13:38
1

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

  • Good answer. +1 – Shoaib Munir Mar 12 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 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 at 6:49

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