import { Component, OnInit, OnDestroy } from '@angular/core';
import { IonHeader, IonButton, IonContent, IonIcon, IonItem, IonLabel, IonList,
IonListHeader, IonCardHeader, IonCardTitle, IonAvatar, IonCardContent, IonTitle, IonCard, IonToolbar, IonInput, IonSearchbar } from '@ionic/angular/standalone';
import { Router } from '@angular/router';
@Component({
selector: 'app-drift-bottle',
template: `
Drift Bottle
`,
styleUrls: ['./drift-bottle.component.scss'],
standalone: true,
imports: [IonHeader, IonToolbar, IonTitle, IonContent,
IonList, IonListHeader, IonItem, IonCardTitle,
IonLabel, IonIcon, IonButton, IonCardContent, IonAvatar,
IonInput, IonSearchbar, IonCard, IonCardHeader
]
})
export class DriftBottleComponent implements OnInit, OnDestroy {
constructor(private router: Router) { }
ngOnInit(): void {
const audioElement = document.getElementById('backgroundAudio') as HTMLAudioElement;
if (audioElement) {
audioElement.play();
}
}
ngOnDestroy(): void {
const audioElement = document.getElementById('backgroundAudio') as HTMLAudioElement;
if (audioElement) {
audioElement.pause();
audioElement.currentTime = 0; // Reset the audio to the beginning
}
}
goTab1(): void {
this.router.navigate(['tabs/tab1']);
}
addRipple(event: MouseEvent): void {
const container = event.currentTarget as HTMLElement;
const rect = container.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
// 创建涟漪元素
const ripple = document.createElement('span');
ripple.classList.add('ripple');
// 设置涟漪的位置和大小
ripple.style.left = `${x}px`;
ripple.style.top = `${y}px`;
ripple.style.width = ripple.style.height = '100px'; // 可根据需要调整
// 添加到DOM并触发动画
container.appendChild(ripple);
// 动画结束后移除涟漪元素
setTimeout(() => {
ripple.remove();
}, 600); // 应与CSS动画时间相匹配
}
}