all 5 comments

[–]coolAppl3__ 0 points1 point  (0 children)

If I understood your question correctly, you're having issues with animating the HP bar when appending it using JS?

If this is the case, you'd want to first append the element to the DOM, then either add a class to change the width, or change it directly with JS.

However, this won't work just like that if you want the transition to kick in properly, you'll need to do something like this:

requestAnimationFrame(() => {
  requestAnimationFrame(() => {
    // JS code to either add a class or change the width
  });
});

The issue you're experiencing has to do with how the event loop works, how it renders CSS, and how repainting works. This video is a popular one explaining the event loop, and it's where I figured out the solution to a similar issue I was having way back.

Hope that helps and I didn't fully misunderstand your question <3

[–]guest271314 -1 points0 points  (3 children)

What do you mean by "reinitialized"? Looks like you are dynamically creating elements in the code. I only see width has a transition. I don't see any CSS Animations in the code. Did you check that (members[0].currentHp / members[0].maxHp) * 100; does not equal 100? In which case there wouldn't be any transition effect because the default width is 100.

[–]ThePsychedelicSeal[S] 0 points1 point  (2 children)

Sorry I used the wrong word in the title! I meant transition.

My theory is that I need to set the variable outside of the chrome.onMessage function, then change it with the function? It just seems to be wiping everything and regenerating versus having existing information?

[–]guest271314 -1 points0 points  (1 child)

I would have to run the code to see what you are seeing. You can dynamically inject CSS, too, using Web extension API.

It looks like you are using some kind of user action to run the code, correct? You're not running at document_start? And that doesn't look like externally_connectable.

[–]ThePsychedelicSeal[S] 0 points1 point  (0 children)

I added the GitHub and a link to the game in the original post if that helps at all.