UNPKG

jqwidgets-framework

Version:

jQWidgets is an advanced Angular, Vue, Blazor, React, Web Components, jquery, ASP .NET MVC, Custom Elements and HTML5 UI framework.

36 lines (29 loc) 1.28 kB
import { Component, ViewChild, AfterViewInit } from '@angular/core'; import { jqxMenuComponent } from 'jqwidgets-ng/jqxmenu'; @Component({ selector: 'app-root', templateUrl: './app.component.html' }) export class AppComponent implements AfterViewInit { @ViewChild('jqxMenu', { static: false }) jqxMenu: jqxMenuComponent; ngAfterViewInit() { this.centerItems(); } centerItems(): void { let firstItem = this.jqxMenu.elementRef.nativeElement.firstElementChild.children[0].firstElementChild; let width = 0; let borderOffset = 2; let allLiElements = this.jqxMenu.elementRef.nativeElement.firstElementChild.children[0].children; for (let i = 0; i < allLiElements.length; i++) { let currentLi = allLiElements[i]; width += currentLi.offsetWidth + borderOffset; } let menuWidth = this.jqxMenu.elementRef.nativeElement.firstElementChild.offsetWidth; let calculatedOffset = (menuWidth / 2) - (width / 2); firstItem.style.margin = '0 0 0 ' + (calculatedOffset).toString() + 'px'; } onResize(event: any): void { let innerWidth = event.target.innerWidth; this.centerItems(); } }