I am creating a web application in angular and I need to add floating menu which permits to increase and decrease font size for people who have vision problem.
Can someone help me how to do that.
Thanks folks
I’am tryong FontService and data- attributes but it doesnt work
3
I would do this by overriding a CSS variable using renderer2
:
// styles.scss
:host {
--app-font-size: 16px;
}
body {
font-size: var(--app-font-size);
}
The updateFontSize
method in the example below takes an explicit size argument, but you could do a mathematical increment/decrement calculation instead.
// font-size.component.ts
export class FontSizeComponent {
constructor(private renderer: Renderer2) {}
updateFontSize(size: string) {
this.renderer.setProperty(
document.documentElement,
'style',
`--app-font-size: ${size}`
);
}
}
<!-- font-size.component.html -->
<button (click)="updateFontSize('18px')">+ Font Size</button>
<button (click)="updateFontSize('14px')">- Font Size</button>