【发布时间】:2020-03-04 03:46:42
【问题描述】:
我创建了一个 Angular 组件,它为照片添加样式和一些动画。我想在另一个组件中使用相同的照片样式,但我不希望动画转移到新组件。
图片上的动画:
.pic
{
position: relative;
height: 13em;
width: 12em;
border-radius: 50%;
margin: 2em auto 0em auto;
animation-name: pop;
animation-duration: 1.5s;
animation-delay: 3.5s;
animation-fill-mode: forwards;
opacity: 0;
}
当我创建一个新组件并将该组件的选择器标签添加到新组件中时,图像会与此动画一起显示。有没有办法可以在我创建的新组件中删除此动画?
很多人都建议这样做:
.pic
{
position: relative;
height: 13em;
width: 12em;
border-radius: 50%;
margin: 2em auto 0em auto;
.anime
{
animation-name: pop;
animation-duration: 1.5s;
animation-delay: 3.5s;
animation-fill-mode: forwards;
opacity: 0;
}
}
当我将这个组件的选择器标签 <app-main-pic></app-main-pic> 添加到另一个组件中时,那个动画类仍然存在于 .pic 上,因此图像仍然会被动画化
新组件:
<div>
<app-main-pic></app-main-pic>
</div>
<body>
</body>
【问题讨论】:
-
为什么不在
class="pic non-animated"这样的非动画图片中添加另一个类,然后添加另一个样式.pic .non-animated { animation: none; opacity: 1 } -
只有一张图片,如果我添加一个名为 .animate 的类,当我在新组件中使用它时,该类仍然存在,因为当我们在另一个组件中使用选择器标签时,它会继承该组件的所有属性/类。
标签: html css angular angular-animations