-1

幅が 768 を超える解像度に対してのみ等列スクリプトを実行したいのですが、どうすればよいかわかりません。

これは私のスクリプトです:

function setEqualHeight(columns) {
   var tallestcolumn = 0;
   columns.each(function () {
      currentHeight = $(this).height();
      if (currentHeight > tallestcolumn) {
         tallestcolumn = currentHeight;
      }
   });
   columns.height(tallestcolumn);
}

$(document).ready(function () {
   setEqualHeight($(" .container > .content"));
});
4

1 に答える 1

2

Math.maxは、複数の値の最大値を見つけるためにjavascriptによってすでに提供されているので、それを使用することをお勧めします。また、それを行うための簡単なjavascriptプラグインを作成することをお勧めします。

$.fn.equalHeights = function () {
    if (screen.width >= 768) {
        var heights = [];
        this.each(function () {
            heights.push($(this).height());
        });
        this.height(Math.max.apply(null, heights));
    }
};

$(function () {
    $('div').equalHeights();
});​
于 2012-12-14T22:41:29.237 に答える