我创建了一个视频并将其作为背景视频添加到我的网站,但我甚至不想将其加载到移动设备上,所以我这样做了:
<video #video autoplay muted loop id="video" *ngIf="currentWidth && currentWidth >= 992">
<source [src]="section.backgroundVideo" type="video/mp4">
</video>
在我的代码里我做到了:
@HostListener('window:resize', ['$event'])
onResize(event: any) {
this.currentWidth = event.target.innerWidth;
}
public currentWidth: number;
constructor(private backgroundImageService: BackgroundImageService) {}
ngOnInit(): void {
this.currentWidth = window.innerWidth;
}
@ViewChild('video', { static: true }) videoplayer: ElementRef;
ngDoCheck(): void {
if (!this.videoplayer) return;
this.videoplayer.nativeElement.play();
}
但它一直找不到录像机。我怀疑是因为即使
当前宽度
大于992px。
有人知道我怎样才能达到我想要的效果吗?