1

I am using scrollIntoView() to go to a selected input. But I set it to top, so I would like to give with an offset to that method.

But this seems not to work I also checked the scrollTo method and did that like this:

this.keyboard.onKeyboardShow().subscribe(() => {
    console.log('document.activeElement!!!!', document.activeElement)
    // document.activeElement.scrollIntoView(true);
    const top = document.activeElement.getBoundingClientRect().top + window.scrollY;
    console.log(top);
    window.scroll(0, top)
    window.scrollTo({
       top: top,
       behavior: 'smooth'
    });
    // document.activeElement.scrollTo(0, 10);
    window.scrollBy(-100, 0);
});

But this will not scroll to that element anymore. Could somebody help me out setting an offset to scrollIntoView()

Sireini
  • 4,142
  • 12
  • 52
  • 91
  • I am confused what exactly you're trying to do. Do you want to scroll above the element or below it? – Chris Sandvik Mar 20 '19 at 14:28
  • @ChrisSandvik scroll to document.activeElement with an offset above. `document.activeElement.scrollIntoView(true);` this is working but with that method I cant give any offset. – Sireini Mar 20 '19 at 14:29
  • Is is scrolling at all when you use `window.scrollTo`? because the offset you are using should probably be negative – Chris Sandvik Mar 20 '19 at 14:33
  • No not scrolling at all and the console.log(top) logs me `436.5238037109375` I also tried this.content with the viewchild(Content) – Sireini Mar 20 '19 at 14:36
  • maybe try setting `left: 0` in the options for scrollTo – Chris Sandvik Mar 20 '19 at 14:38

0 Answers0