关键函数:
.map()
map()把每个元素通过函数传递到当前匹配集合中,生成包含返回值的新的jQuery对象。
function ResizeAll(){
var $box = $('.box');
$box.css({
"height": "auto"
});
$box.height(Math.max.apply(null, $box.map(function () {
return $(this).height();
})));
}
创建好函数后在指定的事件下触发即可。
如下:
// doc ready 时
$(function(){
ResizeAll();
});
// window load 及 resize 时
$(window).on("load resize",function(){
ResizeAll();
});
评论区
发表新的留言
您可以留言提出您的疑问或建议。
您的留言得到回复时,会通过您填写的邮箱提醒您。