Javascript Image onload event binding

前端 未结 1 1970
春和景丽
春和景丽 2020-12-01 14:43

So I have this piece of code that loops through an array and load images and notify when the images is loaded.

for (var i = 0; i < arr.length; i++) {              


        
相关标签:
1条回答
  • 2020-12-01 15:32

    One part of the problem: The event is not called onload, but load.

    imageObj.addEventListener('load', function() { /* ... */ }, false);
    

    Other than that, since i changes outside of the event listener function, you need a closure.

    0 讨论(0)
提交回复
热议问题