I want to scroll to the Y and X center of my element when a certain function is fired. My HTML look like this (i want to scroll to the middle of #viewport):
</div>
<div #viewport class="document-view-port">
<div #viewBox></div>
</div>
Inside my TS i am importing the elements like this(here i try to find the y center):
@ViewChild('viewBox') viewBox: ElementRef;
@ViewChild('viewport') viewport: ElementRef;
The last methods that i try to extract this center point to scroll is:
zoomIn() {
const elementRect = this.viewport.nativeElement.getBoundingClientRect();
const absoluteElementTop = elementRect.top + window.pageYOffset;
const middle = absoluteElementTop - (elementRect.height / 2);
this.viewport.nativeElement.scrollTo(0, middle)
}
I just can't make it happen, any help would be appreciated
[edit]
The method scrollIntoView() don't do anything in my code. I want to find those cordinates and scroll without using any predefined function