【发布时间】:2020-03-17 02:36:36
【问题描述】:
正如标题所示,我正在尝试在页面加载后向div 元素添加一个类!我有一个条件isTrue,并且在页面加载后执行的角度函数ngAfterViewInit() 使isTrue 的值成为true,然后添加类hideOnLoad。当然我可以使用标准的javascript 或jquery,但我必须以有角度的方式来做。本质上,最终结果应该是,div.index-logo-wrapper 在页面加载后慢慢淡出。我的想法是在加载后添加一个类,逐渐减少opacity 您的输入非常感谢。
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-index-section',
templateUrl: './index-section.component.html',
styleUrls: ['./index-section.component.scss']
})
export class IndexSectionComponent implements OnInit {
isTrue: boolean = false;
public innerWidth: any;
constructor() { }
ngOnInit() {
}
ngAfterViewInit() {
this.innerWidth = window.innerWidth;
if (this.innerWidth < 1000) {
this.isTrue = true;
alert(this.isTrue);
}
}
}
<section class="index-section">
<div class="index-logo-wrapper" [class.hideOnLoad]="isTrue">
<figure>
<img src="assets/icons/logo_mobile.svg" alt=" logo">
</figure>
</div>
<div class="index-media-wrapper">
<div class="media-container">
<iframe src="https://player.vimeo.com/video/128014070?autoplay=1&color=ffffff&title=0&byline=0&portrait=0" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Itaque contra est, ac dicitis; Duo Reges: constructio interrete. Videsne quam sit magna dissensio?
</p>
</div>
</div>
</section>
这是我控制台中的错误:
【问题讨论】:
标签: javascript html angular angular8