jquery - jQ根据周围的div动态设置div的高度
问题描述
我有一个计划页面,我想根据时间段重新格式化。例如:Beatrice 在周一 9 点和 10 点。我想将这些时间块组合起来,在浏览器中看起来像 1 个块。我从一个文件中读取日程表并将其打印到屏幕上。我想用 jQ 来组合它们。我的思考过程:将每个 div 与下一个进行比较,如果它们相同;cnt 上升,我隐藏重复的条目,并使第一个条目的高度覆盖所有重复项。
我到目前为止是这样的:
var cnt = 1;
$('.sched-col').each(function(){ //for each column
$(this).find('.worker').each(function(){ //look for each time block
if ($(this).html() == $(this).next().html()) { //if block is the same as the next
cnt++; //increase the count
$(this).next().css('display', 'none'); //hide the following block
$(this).css('height', boxH * cnt); //adjust height to cover following block
}
});
cnt = 1; //reset counter for new column
});
我知道逻辑实际上并不存在。我需要找到一个名称,计算其下具有相同名称的块的数量,隐藏这些块并相应地调整高度,然后为每个新名称重置计数。我只需要一些帮助才能将其放入代码中。
解决方案
在玩了一些代码行之后,事实证明您必须保留最后一个具有相同名称的条目,并拉伸该条目以填充空间工作代码:
var boxH = $('.worker').outerHeight();
var cnt = 1; //initial count of first name encounter
$('.sched-col').each(function(){ //for each column
$(this).find('.worker').each(function(){ //find the worker blocks
if ($(this).html() == $(this).next().html()) { //if next block is same name
cnt++; //increase count
$(this).css('display', 'none'); //remove the current block
}
else { //two blocks are not the same name
$(this).css('height', boxH * cnt); //stretch to cover duplicate block spaces
cnt = 1; //reset count
}
});
});
推荐阅读
- javascript - POST 方法返回空对象
- git - git p4 如何在搁置的 cl 获得批准后提交 cl
- python - python中的增量(a * = b)
- java - 从 onResponse Android 返回一个值
- excel - 过渡到新月份期间excel vba中的日期增量
- arcore - 如何删除 ARCore 中的所有平面
- sqlite - sqlite3 fts4“错误数据库表被锁定”
- hyperledger-fabric - Composer 网络安装问题
- angular - 在渲染()循环内调用函数的角度运行时错误:'未定义不是对象(评估 this.watchLocation)'
- java - 在多个junit测试套件上添加拆卸方法