0
$(function () {
    window.addEventListener('message', function (event) {
        switch (event.data.action) {
            case 'toggle':
                if (visable) {
                    $('#wrap').fadeOut();
                } else {
                    $('#wrap').fadeIn();
                    window.health = event.data.health;
                    onloadAnimation(health);
                }
                visable = !visable;
                break;
            default:
                break;
        }
    }, false);
});

progressBar.forEach(function(item) {
  var self = item,

      barValue = self.getAttribute('data-value'),
      skillValue = self.getAttribute('data-skill'),
      effectNum = self.getAttribute('data-effect');
      if (skillValue == "Health") {
        barValue = window.health; //The value wont set here but works on other function
      }
})

window.health value can be set on other function but not this one , someone know how to solve this ? I just check it but its result undefined

  • looks like a timing issue. when you wrap a function in `$(function () {` it isnt called until document is loaded, but your forEach will go-off ASAP, and on top of that the window.health is set by a handler - so that could be some time later i.e. when handler is triggered – developer May 07 '20 at 15:09
  • what shall i do to solve this ? *progressBar.forEach(function(item) {* works by default ? or how to update the value from that *$(function () {* ? – Rust Romania Player May 07 '20 at 15:35

0 Answers0