【问题标题】:How to toggle open and close arrows in HTML in Angular?如何在 Angular 中切换 HTML 中的打开和关闭箭头?
【发布时间】:2022-02-02 01:32:03
【问题描述】:

我有一个很长的列表,想给它扩展和缩回的选项。现在,该功能有效,但我不知道如何为箭头设置动画,以便在页面展开时它指向上方。

  <a id="outline"></a>
  <div
    class="container relative border"
    (click)="this.showOutline = !this.showOutline"
  >
    <h3 class="text-3xl py-4 px-5 text-gray-800">Topic outline</h3>
    <button
      class="absolute bottom-0 border-0 text-2xl z-10 w-full text-center bg-transparent"
    >
      &#8964;
    </button>
    <div class="overflow-hidden">
      <div [innerHtml]="data.outline" [class.collapsed]="!showOutline"></div>
    </div>
  </div>
</section>
  max-height: 200px;
}

.collapsed:before {
  content: '';
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  background: linear-gradient(transparent 150px, rgb(230, 249, 240));
}

Stackblitz Link

【问题讨论】:

  • 请提供一个可重现的最小示例,清楚地展示您面临的问题:stackoverflow.com/help/minimal-reproducible-example 理想情况下,您可以将代码放入在线 IDE 中,例如stackblitz.com,然后有人可以立即着手解决无需先重新创建问题。
  • 我添加了指向 Stackblitz 的链接
  • 它不能正常工作。它不会崩溃任何东西。你能修复它吗?如果我理解得好,一旦它工作正常,你只需要更改箭头的“图标”(向上向下),对吧?
  • edit 您的问题包括您所做的研究,以及您自己尝试解决的问题。例如,关于如何将指向一个方向的箭头设置为指向另一个方向的动画,Stack Overflow 上有数百个问题。
  • 所以它确实有效,但不幸的是它很微妙。当你第一次去它时,你会在底部看到一个绿色的色调。这与我们正在使用的页面相匹配。单击箭头时,绿色渐变消失,表示内容已展开。

标签: html angular animation expandablelistview


【解决方案1】:

使用 ngIf 像这样尝试。要了解有关 *ngIf 的更多信息,请参阅 https://angular.io/api/common/NgIf

<section>
  <a id="outline"></a>
  <div
    class="container relative border"
    (click)="this.showOutline = !this.showOutline"
 >
<h3 class="text-3xl py-4 px-5 text-gray-800">Topic outline</h3>
<button
  class="
    absolute
    bottom-0
    border-0
    text-2xl
    z-10
    w-full
    text-center
    bg-transparent
  "
>
<span *ngIf="showOutline; else upwardsArrow" >
  &#8964;
</span>
<ng-template #upwardsArrow>
  &#8964; <!-- replace with upwards arrow -->
</ng-template>

  
</button>
<div class="overflow-hidden">
  <div [innerHtml]="data.outline" [class.collapsed]="!showOutline"></div>
</div>

【讨论】:

  • 文件中的“else”不起作用
猜你喜欢
  • 2017-05-06
  • 1970-01-01
  • 2020-04-22
  • 2021-03-01
  • 1970-01-01
  • 2022-09-28
  • 1970-01-01
  • 1970-01-01
  • 2019-07-06
相关资源
最近更新 更多