Angular Object doesn't support property or method 'scrollTo' with Internet Explorer

Viewed 3539

In my Angular 6 application i have a method which executes an auto scroll into the page. In Chrome it works fine, but in Internet Explorer (11) i get the following error:

ERROR TypeError: Object doesn't support property or method 'scrollTo'

This the function in my component:

 autoScroll(step) {
    setTimeout(() => {
        let element = document.getElementById(step.stepId);
        if (element) {
            let el= document.getElementsByClassName("elements") && document.getElementsByClassName("elements")[0];
            if (el) {
                el.scrollTo({
                    top: 50,
                    behavior: "smooth"
                });
            }
        }
    })
}
2 Answers

document.querySelector('').scrollTop = 50

Use scrollTop, hope this will help you to resolve the problem.

Try to enable support for IE 11 in polyfills.ts file.

Related