Sort by image resolution in gallery

前端 未结 5 901
-上瘾入骨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:43

    Could something like this help?

    var imgs = document.getElementsByClassName("imgs");
    
    var height = imgs.clientHeight;
    var width = imgs.clientWidth;
    
    imgs.sort(function(a, b){
      return a.height - b.width;
    });
    

    or using node.js:

    imgs.sort(function(a, b) {
      return fs.statSync(a).size - fs.statSync(b).size;
    });
    

提交回复
热议问题