Scroll to Top after Adding Product to Cart?

by brackfost   Last Updated July 23, 2019 14:09 PM

I'd like the user to be scrolled to the top of the product page upon successfully adding a product to their cart, so that they can see the success message.

What would be the best way to accomplish this?

Tags : magento2


Answers 1


Try this code in your custom js

require(['jquery', 'jquery/ui'],function($){
    $('[data-block="minicart"]').on('contentLoading', function (event) {    
        $('[data-block="minicart"]').on('contentUpdated', function ()  {
            $('html, body').animate({scrollTop:0}, 'slow');
        });
    });
});
Ranganathan
Ranganathan
July 23, 2019 13:38 PM

Related Questions