Problem Solved.
If you have the same issue, check if the content inside the child doesn't get loaded late. Like in my case the image inside gets loaded after it is in the viewport. That means it hasn't had a width until then.
I solved it that way:
this code snipped waits for the images to load in order to get the width
var counter = 0;
$(document).ready(function(){
images_length = $('.gallery-image').length;
//i needed to wait until all images have loaded so i picked the last image that fires the last event.
$('.gallery-image').on("load", function() {
if(counter == images_length -1){
var slides = $('.gallery-slide', this);
for (let i = 0; i < slides.length; i++) {
console.log(slides[i].offsetWidth);
}
}
counter++;
});
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…