Closed Bug 1774754 Opened 3 years ago Closed 3 years ago

window.scrollTo with smooth behavior is no longer working

Categories

(Core :: Panning and Zooming, defect)

Firefox 101
defect

Tracking

()

RESOLVED DUPLICATE of bug 1519339

People

(Reporter: philippemp11, Unassigned)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0

Steps to reproduce:

I'm calling the function below with smooth = true

ABCD.scroll_to_element = function(elem, voffset, hoffset, smooth){
const etop = elem.getBoundingClientRect().top;
const btop = document.body.getBoundingClientRect().top;
const eleft = elem.getBoundingClientRect().left;
const bleft = document.body.getBoundingClientRect().left;
window.scrollTo({
top: etop - (btop + voffset),
left: eleft - (bleft + hoffset),
behavior: smooth ? 'smooth' : 'instant'
});
}

Actual results:

Nothing, it is not scrolling to the element in param

Expected results:

It should have scrolled to the element in param

User Agent String:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0

Note:

  • everything is working well with behavior: 'instant'
  • to be more accurate, it is sometimes working with behavior: 'smooth' and sometimes not. From what I observed so far, it depends on where the <a href="..."> tag calling the function is located:
    • if the <a> tag is located in a <div > (display:inline-block) directly in the HTML page body, it is working well
    • if the <a> tag is located in nested blocks with a <div> (position:fixed) at the root level, it is not working properly
  • I tested with Edge and Chrome and everything is working well

I do not have exact reproduction steps so far. I'm happy to help on more in details reproduction steps, please let me know

Component: Untriaged → Panning and Zooming
Product: Firefox → Core

If you can upload an html file that reproduces for you that would be helpful.

Flags: needinfo?(philippemp11)
Attached file scroll_to.html
Flags: needinfo?(philippemp11)

I finally managed to identify the root cause
If I get document.body.style.overflowY = 'auto', it’s working well, but if I get document.body.style.overflowY = 'hidden' it is not scrolling to the element

Please find the HTML file in attachment

Thanks for the testcase. Sounds like you may be running into bug 1519339.

Yes this is the same issue, thank you

Thanks, will close as duplicate. That bug has been around for a long time but this is a good reminder to put it on the roadmap for fixing.

If you have examples of production websites that you know to be affected, please feel free to mention them, that helps make the case for fixing it sooner.

Status: UNCONFIRMED → RESOLVED
Closed: 3 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: