-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
Firstly, great polyfill – it works perfectly for scrollTo, however I'm unable to get scrollIntoView working.
Environment
IE 11 on Windows 10
Expected behaviour
When I call HTMLElement.scrollIntoView, I expect the page to scroll to the element.
Current Behaviour
When I call HTMLElement.scrollIntoView nothing happens; no console errors, no scroll, nothing.
Implementation
I have a function which I call, that looks like this:
async function scrollToSection(section) {
if (!('scrollBehavior' in document.documentElement.style)) {
console.log('Loading scroll behaviour polyfill...');
await import('scroll-behavior-polyfill');
}
const container = document.querySelector(`.Section--${section}`);
container && container.scrollIntoView();
}My scrolling element is a custom element (so not the html or body elements). Do you think this is what could be causing the issue?
As a work-around, I've done this:
async function scrollTo(scrollContainer, {x, y, behavior = 'smooth'}) {
if (!('scrollBehavior' in document.documentElement.style)) {
console.log('Loading scroll behaviour polyfill...');
await import('scroll-behavior-polyfill');
}
scrollContainer.scrollTo({left: x, top: y, behavior});
}
function scrollToSection(section) {
const scrollContainer = document.querySelector('#root-app');
const container = document.querySelector(`.Section--${section}`);
if (container) {
const {top} = container.getBoundingClientRect();
scrollTo(scrollContainer, {y: top});
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels