2

I have a problem with Buttons in Pagination. If the user clicks the button, it reloads the page with loader and settles down at the current page scroll position. Is there any method to forcefully load to jump to the top of the page?

The code I have tried so far is

    jQuery(document).ready(function() {

    jQuery('a.action.next,a.action.previous,li.item.current,li.item a.page').click(function() {
          setTimeout(function(){    
                jQuery("html, body").animate({ scrollTop: 0 }, "slow");
          }, 6000);           
    });
    
});

Any help will be appreciated!

3 Answers 3

2
jQuery(document).ready(function() {
    jQuery(document).on("click", 'a.action.next,a.action.previous,li.item.current,li.item a.page', function(event) { 
          setTimeout(function(){    
                jQuery("html, body").animate({ scrollTop: 0 }, "slow");
          }, 6000);           
    });
    
});

Note: 3000 = 3 second. Adjust 3000 according to your need.

7
  • Hi, @Chirag thanks for the reply back, tired your code still no success. It's on the same page and still not moving up. Aug 13, 2020 at 13:59
  • Adjust 3000 according to your need. try 5000. You are getting late reply from server response so. Aug 13, 2020 at 14:30
  • adjusted to 6000, on the first click time alone it's working on any class after second or third click it's not working the same issues is arsing. Aug 14, 2020 at 2:43
  • @ScriptHost, Please try updated answer. Aug 14, 2020 at 5:37
  • Have updated the code, please check and let me know. Aug 14, 2020 at 6:25
2

Try this code:-

   <script type="text/javascript">
        require(['jquery'], function (jQuery) {
          jQuery(document).ready(function ($) {
            $('#cpa-scroll-to-desc').click(function (event) {
              event.preventDefault();
              $('html,body').animate({
                scrollTop: $(".box-collateral").offset().top - 120}, 'slow');
            });
          });
        });
      </script>
1
  • Can you describe with my class Aug 14, 2020 at 11:32
1

I have tried this code in list.phtml and it works perfectly

<script type="text/javascript">
    require([
        'jquery'
    ], function ($) {
        jQuery("ul.pages-items a").each(function(index) {
            jQuery(this).click(function() {
                jQuery("html, body").animate({ scrollTop: 0 }, "slow");         
            });     
        }); 
    });
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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