简体   繁体   中英

How to toggle open and close arrows in HTML in Angular?

I have a long list and want to give it the option of expanding and retracting. Right now, the functionality works, but I don't know how to animate the arrow so that it points up when the page is expanded.

  <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

Try it like this using ngIf. To read more about *ngIf see 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM