Scrollintoview To Apply To Iframe Only
I have an element inside of a page with scollbars, which is brought into view on page load via JS call to element.scrollIntoView() - and this works fine, as expected. Now, if I pl
Solution 1:
Figured it out. I can set element's parent's scrollTop
to element's own offsetTop
. This will make parent scroll to element's position and effect will be local to IFRAME.
Solution 2:
The above solution will indeed work but you wouldn't be able to apply smooth scrolling behaviour. Ran into the same issue and figured you can actually fix by using scrollTo
, and then you'd be able to add a smooth scrolling.
Assuming container
, and element
are respectively the DOM elements for the fixed size container and the element you want to scroll to:
container.scrollTo({
top: element.offsetTop,
behavior: 'smooth',
})
It's then up to you to choose whether you want to get the given DOM elements using jQuery or references.
Solution 3:
How about this:
window.parent.scrollTo(0,0);
Post a Comment for "Scrollintoview To Apply To Iframe Only"