Sort by image resolution in gallery

前端 未结 5 903
-上瘾入骨i
-上瘾入骨i 2020-12-01 17:11

I made this gallery a while ago: https://jsfiddle.net/5e9L09Ly/

Don\'t worry it won\'t upload anything.

I made that you can sort by file size, but I want to

5条回答
  •  爱一瞬间的悲伤
    2020-12-01 17:40

    You should process images in batches, say 20 at a time.

    On image load you store name and resolution for each of the images in an array, then destroy the images to free up memory

    When you get the 20 onload or onerror, you process the next batch.

    When all is done, you sort the array and display the images .

    If there are hundreds or thousands of them, you need to paginate the gallery

    It should be simple, since you already have the array with all image names and resolutions at hand.

    just set some variables for starting offset and page size and slice() the array to get the subset you need (the "current page")

提交回复
热议问题