I am working on a project recently, and there is an image in an h5 page that is dynamically taken from the backend
How to set the width? I initially used num=$("#lf").find("img").length;//all the pictures on the page and then set the scroll width to each picture width *num+80px but found that it was changed After it is converted into jsp, num cannot be obtained at all. How should the width here be handled? Thanks
Does dynamically fetching data from the backend refer to AJAX request data?
I think we need to confirm the following two points:
1. Is the DOM element loaded when setting the width?
2. Is the AJAX request returned when setting the width? AJAX is asynchronous;
num=$("#lf").find("img").length, the number of pictures
width num+80px, it should be (num+80) + 'px'
still can't be obtained It should be before js loads the picture, that is to say, the code has been executed before the picture comes out. But try using num as the judgment condition. If num > 0, at least one picture has been loaded. This is safer.