'JQuery wait for createElement (image) - http/2 error
I switched to HTTP/2 and now I sometimes get errors when appending new images.
Currently using JQuery.
var logoCarousel = {
initCarousel: function () {
...
var rows = $('.section.section--logos .content .logo__row');
var row1 = $(rows[0]);
// LOOP ELEMENTS
$.each(initUsedElements, function () {
self.appendElement(this, row1, 1);
// self.appendElement(this, row2, 2);
});
},
appendElement: function (elementsInput, row, rowNum) {
if (row.attr("data-actual-count") != row.attr("data-max-count") && elementsInput.flag == false) {
let img = document.createElement("img");
img.setAttribute('src', elementsInput.url);
img.setAttribute('alt', '');
img.setAttribute('data-actual-id', elementsInput.id);
img.setAttribute('class', 'client__logo');
row.prepend(img);
row.attr("data-actual-count", parseInt(row.attr("data-actual-count")) + 1);
elementsInput.flag = true;
elementsInput.lastRow = rowNum;
return elementsInput;
}
},
};
I am getting net::ERR_HTTP2_PROTOCOL_ERROR.
If I understand correctly my problem is I do not wait in the $.each-loop until the image is loaded.
How can I do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
