How to find the height of a dynamic element with Angularjs?

Asked

Viewed 311 times

5

I have a menu with accordion effect I need to find out how high this menu, remembering that the height is dynamic, IE when it has some open element it gets bigger.

After that it is necessary to discover the position of the element clicked in relation to the scroll.

Basically what I’m trying to do is when clicked on the item I recognize the height of the menu and its position in scroll,then I move up the screen x% to center the content clicked.

Any help is welcome, thank you

  • The answer given is correct? Solved your problem? Don’t forget to vote yes and choose the correct answer.

1 answer

1

Actually what you need is an angular component called $anchorScroll.

When called, it Scrolls to the element Related to the specified hash or (if omitted) to the Current value of $Location.hash(), According to the Rules specified in the HTML5 spec. (Google)

The boring part of this component is that you can’t use it in conjunction with ngAnimate to make animations.

If you want to do with a little animation, you can take a look in this example from Stackoverflow gringo, which is simple but expresses well what you want.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.