A. Gladkiy
A. Gladkiy

Reputation: 3450

scrollIntoView on element with height = 0 in angular 2+

I have the following html:

<div class="row-20 st-margin" *ngIf="role == 'Administrator'" id="hr-data">
  <div class="col-md-12"></div>
</div>

and after ajax call I have that div visible. Then I want to scroll to that div by click:

document.getElementById('hr-data').scrollIntoView({behavior: 'smooth'});

but it doesn't work.

So, how can I fix that?

Upvotes: 0

Views: 129

Answers (1)

A. Gladkiy
A. Gladkiy

Reputation: 3450

For some reasons, div class="row-20 st-margin" has no height. I moved id to div class="col-md-12" and it works fine:

<div class="row-20 st-margin" *ngIf="role == 'Administrator'">
  <div class="col-md-12" id="hr-data"></div>
</div>

Upvotes: 1

Related Questions