Complete not working?
-
imgmas=[]; var el=document.querySelectorAll('.bigslider .slider__item img') for (let i=0; i<=el.length;i++ ){ if (el[i].complete) { var tmp=get_dimensions(el[i]); imgmas.push(tmp); } else { el[i].onload=function(event) { event=event || window.event; var el=event.target || event.srcElement; var tmp=get_dimensions(el);<code lang="javascript"> </code> imgmas.push(tmp); } } }
When I load only one element, everything works fine, I load the array there and call the function for each element one by one, I don’t like this line of codeif (el [i] .complete)
I know why ..., like I also give only one element and gives this error
review.js:197 Uncaught TypeError: Cannot read property 'complete' of undefined
JavaScript Anonymous, Mar 20, 2019 -
First, there is a direct road to figuring out how to get the last element of an array.
i & lt; = el.length;
Second, like Roman said, you overwriteel
if:
!! el [i] .complete === false.
Felix Caldwell -
i & lt; = el.length-1
Anonymous
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!