首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >jQ根据周围的div动态设置div高度

jQ根据周围的div动态设置div高度
EN

Stack Overflow用户
提问于 2018-06-02 03:54:31
回答 1查看 36关注 0票数 1

I have a schedule page,我想根据时间段重新格式化。例如:比阿特丽斯在周一9点和10点。我想把这两个时间段组合起来,在浏览器中看起来像一个区块。我从文件中读取时间表,并将其打印到屏幕上。我想用jQ把它们结合起来。我的想法是:将每个div与下一个div进行比较,如果它们是相同的;cnt向上,我隐藏重复的条目,并使第一个条目的高度覆盖所有重复的条目。

到目前为止,我得到的是:

代码语言:javascript
复制
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
});

我知道逻辑实际上并不在那里。我需要找到一个名字,计算下面有相同名字的区块的数量,隐藏这些区块并相应地调整高度,然后重新设置每个新名称的计数。我只是需要一些帮助才能把它放入代码中。

My attempt at combining blocks

EN

回答 1

Stack Overflow用户

发布于 2018-06-02 06:37:06

在玩弄了一些代码行之后,结果是你必须保留最后一个同名的条目,并扩展那个条目来填充工作代码的空间:

代码语言:javascript
复制
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
    }
  });
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50650223

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档