A lightweight Angular component for creating beautiful animated avatar borders with GIF support.
English | δΈζ
- π¨ GIF Border Support - Support any GIF as avatar border
- π― Highly Customizable - Full control over size, position, and rotation
- π± Responsive Design - Adapts to any screen size
- β‘ Lightweight - Minimal dependencies, fast loading
- βΏ Accessible - Full ARIA support
- π Standalone - Angular Standalone component support
npm install @luoxiao123/angular-border-avatarimport { Component } from '@angular/core';
import { BorderAvatarComponent, BorderAvatarConfig } from '@luoxiao123/angular-border-avatar';
@Component({
selector: 'app-root',
template: `
<angular-border-avatar
[avatarUrl]="avatarUrl"
[borderConfig]="borderConfig"
size="120px"
></angular-border-avatar>
`,
imports: [BorderAvatarComponent],
standalone: true,
})
export class AppComponent {
avatarUrl = 'https://api.dicebear.com/9.x/avataaars/svg?seed=user1';
borderConfig: BorderAvatarConfig = {
gifUrl: 'https://example.com/border.gif',
avatarScale: 0.7, // Avatar occupies 70% of container
topOffsetRatio: 0.15, // 15% of container height from top
leftOffsetRatio: 0.15, // 15% of container width from left
borderRadius: '50%', // Circle shape
rotate: 0, // Rotation angle in degrees
};
}| Property | Type | Default | Description |
|---|---|---|---|
avatarUrl |
string | null | undefined |
null |
Avatar image URL. When null/undefined, uses default image |
borderConfig |
BorderAvatarConfig | null | undefined |
null |
Border configuration. When null/undefined, border is hidden |
size |
string |
'120px' |
Container size (px, rem, %, vw, etc.) |
altText |
string |
'Avatar' |
Image alt text |
clickable |
boolean |
false |
Whether avatar is clickable |
lazyLoad |
boolean |
true |
Enable lazy loading |
defaultImageUrl |
string |
SVG placeholder | Default image when loading fails |
interface BorderAvatarConfig {
gifUrl: string; // Border GIF URL (required)
avatarScale: number; // Avatar scale ratio (0.3-0.9)
topOffsetRatio: number; // Vertical offset ratio (-0.2~0.2)
leftOffsetRatio: number; // Horizontal offset ratio (-0.2~0.2)
borderRadius?: string; // Border radius (default: '50%')
rotate?: number; // Rotation angle (default: 0)
}| Event | Type | Description |
|---|---|---|
imageLoad |
EventEmitter<void> |
Emitted when avatar image loads |
imageError |
EventEmitter<string> |
Emitted when image fails to load |
avatarClick |
EventEmitter<MouseEvent> |
Emitted when avatar is clicked |
| Method | Description |
|---|---|
recalculate() |
Recalculate dimensions when container size changes |
<angular-border-avatar
[avatarUrl]="'https://example.com/avatar.jpg'"
[borderConfig]="borderConfig"
size="120px"
></angular-border-avatar><angular-border-avatar
[avatarUrl]="avatarUrl"
[borderConfig]="borderConfig"
[clickable]="true"
(avatarClick)="onAvatarClick($event)"
(imageError)="onImageError($event)"
></angular-border-avatar>onAvatarClick(event: MouseEvent) {
console.log('Avatar clicked!', event);
}
onImageError(error: string) {
console.error('Failed to load image:', error);
}<div [style.width]="containerWidth + 'px'">
<angular-border-avatar
#avatar
[avatarUrl]="avatarUrl"
[borderConfig]="borderConfig"
[size]="'100%'"
></angular-border-avatar>
</div>import { ViewChild } from '@angular/core';
import { BorderAvatarComponent } from '@luoxiao123/angular-border-avatar';
export class MyComponent {
@ViewChild(BorderAvatarComponent) avatar!: BorderAvatarComponent;
changeDimensions() {
// When container size changes, call recalculate method
this.avatar.recalculate();
}
}const circleConfig: BorderAvatarConfig = {
gifUrl: 'https://example.com/border.gif',
avatarScale: 0.7,
topOffsetRatio: 0.15,
leftOffsetRatio: 0.15,
borderRadius: '50%',
};const squareConfig: BorderAvatarConfig = {
gifUrl: 'https://example.com/border.gif',
avatarScale: 0.75,
topOffsetRatio: 0.125,
leftOffsetRatio: 0.125,
borderRadius: '10px',
};const rotatingConfig: BorderAvatarConfig = {
gifUrl: 'https://example.com/border.gif',
avatarScale: 0.65,
topOffsetRatio: 0.175,
leftOffsetRatio: 0.175,
borderRadius: '50%',
rotate: 45,
};Avatar Size = Container Size Γ avatarScale
Top Offset = Container Height Γ topOffsetRatio
Left Offset = Container Width Γ leftOffsetRatio
- avatarScale: Set between 0.6-0.8 for optimal appearance
- Offset Ratios: Keep within Β±0.2 range to control avatar position
- borderRadius: Match the avatar shape (50% for circle, other values for rectangle)
- GIF Size: Keep GIF file size under 1MB for better performance
- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
MIT
Contributions are welcome! Feel free to submit issues and pull requests.
If you have any questions, please open an issue on GitHub Issues.