Magento 2 – Prevent Scroll Top on Confirm jQuery or Remove Product from Mini Cart

jquerymagento2scroll

In Magento 2, I've seen that when we click on the button remove a product from the mini cart, we will be scrolled to the top of the site.

enter image description here

I've see that this one is because of <a href="#"> tag, and replace with <a href="javascript:;">.

enter image description here

But that isn't enough, it still has the problem, so I've debugged it deeper and found that this confirm from jquery have responsibility for this.

I just need to remove that confirm code, and it won't scroll top anymore.

enter image description here

But unlucky that I can't find any solution to prevent the scroll to top from the confirm jquery library.

Can someone help me please? Thanks.

Best Answer

I've debug deeper and found that this is because when you click on remove product button, magento modal use js to add _has-modal class to <body> and also this activate some css related to _has-modal class.

For specific, this line is responsible for scroll top problem:

body._has-modal {
   overflow: hidden;
}

So i've create a css to override that part and it resolved the problem.

body._has-modal {
    overflow: initial;
}

enter image description here

Hope it help someone who have this problem too.

Related Topic