Just add these two events to the element
let top = 0; // Store the current scrollbar height and lock body onMouseEnter () {top = window.scrollY; document.body.style.position = 'fixed'; document.body.style.top = -top + 'px'; document.body.style.width = '100%'; document.body.style.overflowX = 'scroll'; }, / / mouse left the target element, release the lock body, restore the scroll bar height onmouseleave () {document. Body. Style. The position = ' '; document.body.style.top = ''; document.body.style.width = ''; document.body.style.overflowY = 'unset'; window.scrollTo(0, top); },Copy the code