I wrote a popup with an overlay (not like regular graphic displays) where the user clicks and the overlay covers the screen, which retrieves the image for display.
The problem is that when the user clicks the close button, my function disappears due to the image and overlay, and then deletes them. When I call the .remove()
function, the browser then focuses on the body tag and scrolls to the top of the page.
I tried a workaround by capturing the coordinates of offset.top
and storing them in the attribute of the element that the user clicks on, and when the popup closes even after the function was called. remove()
, I use the scrollTo()
function to return the correct scroll position (which for some reason will overshoot and scroll the element up).
function newsPopup(obj){ var itemID = $(obj).attr('itemID'); var storyNumber = $(obj).attr('storyNumber'); var offset = $(obj).offset(); var roundedOff = Math.round(offset.top); $(obj).attr('scrollMeBack', roundedOff); function overlayRemove(){
Why .remove()
function cause a jump at the top of the page? Even when working with scrollTo
it looks scrollTo
, as the material disappears, but jumps to the top of the screen, and then returns to the element in question.
source share