简体   繁体   English

在多个CSS类的EACH元素上具有相等的高度和窗口调整大小功能

[英]Equal height and window resize function on EACH element of the multiple CSS classes

Not an expert on coding, find a solution on how to use "each". 不是编码专家,请找到有关如何使用“每种”的解决方案。 But then suck on combining with the equal heigh line. 但是,然后吸取与等高线相结合。 Please help! 请帮忙! After everything load, "slick-list" is the one that equal with the height of the tallest slide. 加载完所有内容后,“滑动列表”就是与最高幻灯片的高度相等的列表。 Then I want that/ each "carousel-wrap-x band" equal on it own "slick-list". 然后,我希望每个“轮播-环绕-x乐队”在其自己的“光滑列表”上均相等。

 $("[class*='carousel-wrap-'] .carousel").each(function() { $(this).slick({ appendArrows: $(this).siblings('.carousel-control'), other functions }); $(this).siblings({ var offsetHeight = $(this).siblings('.slick-list').outerHeight(); $(this).siblings('.carousel .band').outerHeight(offsetHeight); $( window ).resize(function() { $(this).siblings('.carousel .band').css("height", "100%") var offsetHeight = $(this).siblings('.slick-list').outerHeight(); $(this).siblings('.carousel .band').outerHeight(offsetHeight); }); }); }); 
 <div class="carousel-wrap-1"> <div class="carousel-control"></div> <div class="carousel"> <div class="slick-list"> <div class="band">1</div> <div class="band">2</div> <div class="band">3</div> </div> </div> </div> 

Not sure I totally understand what you're going for - definitely a lot going wrong here, I applaud your adventurousness if you're relatively new to code though! 不确定我是否完全了解您的工作-这里肯定有很多错误,如果您对代码比较陌生,我会为您的冒险而称赞! I'm familiar with both slick slider and jquery's "each" - so here are a few things I see going wrong. 我对光滑的滑块和jquery的“每个”都很熟悉-所以这是我认为出错的几件事。

The jquery function .each() takes in two parameters - index and element. jQuery函数.each()接受两个参数-index和element。 I think index is the index of the array you'd get back from $("[class*='carousel-wrap-'] .carousel") - I don't generally use that - and element is the element returned by the selector, sans jquery wrappage. 我认为index是您从$(“ [class * ='carousel-wrap-'] .carousel”)返回的数组的索引-我通常不使用它-而element是由选择器,无jQuery包装。

I can't remember what "this" is going to refer to but looking in my own code I'd be using the $(element) in its place eg 我不记得“ this”将要指的是什么,但是在我自己的代码中,我将使用$(element)代替它,例如

$(".selector").each(function(index, element) {
    $(element).addClass("do-a-thing");
});

As for this bit - $(this).siblings( {... } ); 至于这个位-$(this).siblings({...}); First off, siblings takes in a selector - I'm guessing that passing in a block of code like that just blows it up? 首先,兄弟姐妹需要一个选择器-我猜想传递这样的代码块会把它炸掉吗?

Second, the containing .each()'s parent selector is for "[class*='carousel-wrap-'] .carousel" - so that'd look for the siblings of the carousel, which is just carousel-control, which is clearly not what you're looking for. 其次,包含的.each()的父选择器用于“ [class * ='carousel-wrap-'] .carousel”-因此,它会寻找该carousel的兄弟姐妹,这只是carousel-control,显然不是您要找的东西。

Lastly, the window event listener - if you want that to apply to a specific object, I believe you'll need .bind(this) (or .bind($(element)) or whatever) after the function call like so: 最后,窗口事件侦听器-如果您希望将其应用于特定对象,我相信您在函数调用之后需要.bind(this)(或.bind($(element))或其他任何东西),如下所示:

  $( window ).resize(function() {
    $(this).siblings('.carousel .band').css("height", "100%")
    var offsetHeight = $(this).siblings('.slick-list').outerHeight();
    $(this).siblings('.carousel .band').outerHeight(offsetHeight);
  }.bind(this));

Otherwise I think "this" will be the window 否则我认为“这”将成为窗口

Still not 100% on what you're trying to do - educated guess, you're trying to make the bands inside slick list equal height, and slick-list is a carousel slide (so it's a slide with 3 columns or somesuch)? 仍然不是您尝试执行的操作的100%-有根据的猜测,您正在尝试使光滑列表中的带子高度相等,而光滑列表是旋转木马幻灯片(所以它是3列或类似的幻灯片)?

If that's the case, have you tried experimenting with making it a flex box? 如果是这种情况,您是否尝试过将其制成弹性盒? Could be a problem you could solve with CSS instead of javascript, and that's always preferable! 可能是您可以使用CSS而不是javascript解决的问题,这始终是可取的!

Good luck and I hope that helps! 祝您好运,希望对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM