offsetTop return 0 after call back


#1

Hello guys,

I’m developing a Bible App that, when I click in some verse, it opens (in the same view) the same verse but in another Bible Translation. So, if the Verse is the number 30, for example, when I click in the verse, the another translation is open and scrolled until this verse. I made it by put and “id” in the verse div.

For every first time that I click in the verse, all happens fine. But when I click again in this verse, it open the translation version but it doesn’t go until the selected verse. I already checked and the selected verse is passed, but the offsetTop returns 0.

EXAMPLE:
At the first time that I click in the verse, offsetTop return 3387. If, in the synchronized version I click in other verse, it returns to the original version but don’t scroll until this verse. offsetTop just return’s 0. So, I try to click, in this original version (the same that before was OK), in another verse, It sincronize again but without scroll.

My code to take the id position and scroll to the verse:

      let yOffset = document.getElementById("verse-"+verse).offsetTop;
      console.log(yOffset); //The first time return a correct number and the follow times return 0... :(
      this.content.scrollTo(0, yOffset, 1000);

Anyone have a idea about how to do?

To have a idea about how the APP works, you can download it in APP Store or Google Play.

Thank you very much!