Skip to content

IE 11 HTMLElement.scrollIntoView() doesn't execute #12

@enijar

Description

@enijar

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});
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions