Scroll to Top after Adding Product to Cart?
-
08-03-2021 - |
Question
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?
Solution
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');
});
});
});
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange