-1
목록에있는 요소의 수에 따라 동적 인 높이가 다른 여러 정렬되지 않은 목록이 있다고 가정 해 보겠습니다. 가장 높은 높이를 얻으려면 어떻게해야합니까?jQuery - 최상위 요소 높이 높이기
저는 이미 this 게시물의 도움으로 목표를 달성하려고했습니다.
var max = -1;
$('.navi-main li').each(function() {
max = Math.max(max, $(this).height());
});
alert(max);
또는 하나 :
은 그래서 이것은 내가 다음과 같은 시도 할 수
$.fn.getMax = function() {
/* create array of heights*/
var heights = $(this).map(function(i, e) {
return $(e).height();
}).get();
/* get max height*/
var max = Math.max.apply(this, heights);
/* get index of max in array*/
var pos = $.inArray(max, heights)
/* return element with proper index*/
return this.eq(pos);
};
$('.navi-main li').getMax().css({backgroundColor: "red"});
귀하의 HTML 코드를 게시하십시오 ... –
지금까지 시도한 것을 게시하십시오. 참조 게시물을 제대로 따르지 않았거나 오류가있을 수 있습니다. –
죄송합니다. 방금 일부 코드를 추가했습니다. – user3414687