なんてこった!
次のjQuery関数を見てみましょう。
$.fn.getMax = function() {
return this.height(Math.max.apply(this, $(this).map(function(i, e) {
return $(e).height();
}).get()));
};
すべてのセレクターの最も高い高さを返し、設定します。object
しかし、 (高さではなく)最も高い値を返したい場合はどうでしょうか。
したがって、次のように関数を呼び出すと、次のようになります。
$(selector).getMax().css({backgroundColor: "indigo"});
...最も高い高さの要素はどのように取得されbackgroundColor
ますか?
アップデート
Amareswar$.makeArray
が言ったように、私は今それをで管理しました。
$.fn.getMax = function(prop) {
var max = $.makeArray($(this)).sort(function(a, b) {
return (parseInt($(b).css(prop), 10) || 1) - (parseInt($(a).css(prop), 10) || 1);
}).shift();
return $(max);
};
乾杯!