How to scroll element into view when it's clicked

前端 未结 7 1837
甜味超标
甜味超标 2020-12-11 02:30

Am looking for something similar to scrollIntoView() within Ionic2 to use when I click on a button, for example.

None of the methods detailed in ion-content help.

7条回答
  •  借酒劲吻你
    2020-12-11 02:45

    I was trying to do this in Ionic 3 and due to the fact that .offsetTop was returning10 (the padding on the top of the element) instead of the distance to the top of the page (much larger unknown number) I ending up just using .scrollIntoView(), which worked well for me.

    To get the object I used document.getElementById(), but there are many other options on how to get a handle on that.

提交回复
热议问题