admin管理员组文章数量:1128410
in Angular material progress spinner component we can actually set size by setting diameter. I want to know if there is an option to make this diameter responsive so it based on window size.
<mat-progress-spinner [diameter]=24> </mat-progress-spinner>
what I would like to have is:
<mat-progress-spinner [diameter]="some-relative-size"> </mat-progress-spinner>
in Angular material progress spinner component we can actually set size by setting diameter. I want to know if there is an option to make this diameter responsive so it based on window size.
<mat-progress-spinner [diameter]=24> </mat-progress-spinner>
what I would like to have is:
<mat-progress-spinner [diameter]="some-relative-size"> </mat-progress-spinner>
Share
Improve this question
edited Jan 9 at 15:17
Naren Murali
54.9k5 gold badges40 silver badges70 bronze badges
asked Jan 8 at 13:18
LaCodeMLaCodeM
8191 gold badge9 silver badges29 bronze badges
2 Answers
Reset to default 3You can create a directive, that adapts to the resize of the screen, but honestly, this should be done simply using media queries
:
mat-spinner {
width: 300px !important;
height: 300px !important;
}
@media screen and (max-width: 768px) {
mat-spinner {
width: 150px !important;
height: 150px !important;
}
}
@media screen and (max-width: 480px) {
mat-spinner {
width: 50px !important;
height: 50px !important;
}
}
Stackblitz Demo
Instead of complicated angular code.
@Directive({
selector: '[dynamicWidth]',
})
export class DynamicWidthDirective {
cdr = inject(ChangeDetectorRef);
spinner = inject(MatProgressSpinner);
percentage = model(1, {
alias: 'dynamicWidth',
});
@HostListener('window:resize', ['$event'])
onResize(event: any) {
this.spinner!.diameter = event.target.innerWidth * this.percentage();
this.cdr.detectChanges();
}
ngAfterViewInit() {
this.spinner!.diameter = window.innerWidth * this.percentage();
this.cdr.detectChanges();
}
}
Stackblitz Demo
You can just declare a variable in your TS file based on the window ?
export class MyComponent {
diameter = window.clientWidth / 10;
}
本文标签: htmlAngular material progress spinner reactiveStack Overflow
版权声明:本文标题:html - Angular material progress spinner reactive - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736724848a1949670.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论