Calculate total width of Children with jQuery

后端 未结 2 1286
北荒
北荒 2020-12-05 08:09

I\'ve tried finding an understandable answer to this, but given up.

In order to have dymnamic content (like blog posts and images) in a hori

2条回答
  •  难免孤独
    2020-12-05 08:55

    You can calculate the width with this one-liner, albeit a tad longer than I would have liked.

    var width = $('.post').map(function(undefined, elem) {
        return $(elem).outerWidth(true);
    }).toArray().reduce(function(prev, curr) {
        return prev + curr;
    }, 0);
    

提交回复
热议问题