I found that if an element is hidden for example using 'display: none'; the offsetTop of that element is 0.
This will cause the page to scroll on top.
I discovered it using WooCommerce that use the display property to hide the product tabs within the single product page.
WooCommerce tabs is one of the ui elements that show the content by clicking on an element. Like accordion.