简体   繁体   English

边框底部的CSS过渡延迟

[英]CSS Transition Delay on border bottom

I have a traditional ecommerce filter list below. 我在下面有一个传统的电子商务过滤器列表。 You have can click to filter products by attributes like shoesize, vendor, etc if your buying shoes. 如果您要购买鞋子,可以单击按鞋子大小,供应商等属性来过滤产品。

My problem has to do with borders. 我的问题与边界有关。 I have every element set to border:bottom . 我将每个元素设置为border:bottom Look at what the line below "Puma" is doing when you click sample code below. 单击下面的示例代码,看看“ Puma”下面的行在做什么。

在此处输入图片说明

 const headings = Array.from(document.querySelectorAll('.refine__heading')); const contents = Array.from(document.querySelectorAll('.refine__content')); headings.forEach(heading => heading.addEventListener('click', addCollapsed)); function addCollapsed(e){ e.target.nextElementSibling.classList.toggle('collapsed'); } 
 /* Reset */ ul { list-style-type: none; padding: 0; } /* Actual Notes */ .refine { width: 200px; border: 1px solid black; } .refine__heading { font-size: 20px; display: flex; justify-content: space-between; border-bottom: 1px solid #dadbd9; padding-left: 5px; padding-right: 5px; } .refine__content { overflow: hidden; transition: max-height 3s ease-out; height: auto; max-height: 100px; border-bottom: 1px solid #dadbd9; /* important */ } .refine label { display: flex; justify-content: space-between; padding-left: 5px; padding-right: 5px; } .collapsed { max-height: 0px; border-bottom: none; /* important */ transition-delay: border-bottom 3s; /* I CANT FIGURE THIS PART OUT*/ transition: max-height 3s ease-out; } 
 <link rel="stylesheet" type="text/css" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css"> <ul class="refine"> <li class="refine__section"> <div class="refine__heading"><span class="refine__heading-content">Vendors</span><i class="fas fa-caret-down"></i></div> <div class="refine__content"> <label><span class="refine__item">Nike</span><span class="count">4</span></label> <label><span class="refine__item">Adidas</span><span class="count">5</span></label> <label><span class="refine__item">Puma</span><span class="count">6</span></label> </div> </li> <li class="refine__section"> <div class="refine__heading"><span class="refine__heading-content">Shoe Size</span><i class="fas fa-caret-down"></i></div> <div class="refine__content"> <label><span class="refine__item">Large</span><span class="count">4</span></label> <label><span class="refine__item">Medium</span><span class="count">5</span></label> <label><span class="refine__item">Small</span><span class="count">6</span></label> </div> </li> </ul> 

EDIT I made the transitions from 0.5 second to 3 seconds so you can see it easier 编辑我从0.5秒过渡到3秒,这样您就可以更轻松地看到它

transition delay doesn't take an attribute. 转换延迟没有属性。 you need to set up a different class for the border-bottom like this: 您需要像这样为border-bottom设置一个不同的类:

.hide-border-bottom{
  transition: border-bottom 0.3s ease-out;
  transition-delay: 0.4s;
}

and add the class to the addCollapsed function like you did .collapsed 像添加.collapsed一样,将类添加到addCollapsed函数中

You have two main problems: First, your transition-delay value only takes time - no CSS property names. 您有两个主要问题:首先,您的transition-delay值仅花费时间-没有CSS属性名称。 Second, your border-bottom cannot be transitioned from none . 其次,您的border-bottom不能从none过渡。

Here's one way of doing things: 这是一种处理方式:

 const headings = Array.from(document.querySelectorAll('.refine__heading')); const contents = Array.from(document.querySelectorAll('.refine__content')); headings.forEach(heading => heading.addEventListener('click', addCollapsed)); function addCollapsed(e){ e.currentTarget.nextElementSibling.classList.toggle('collapsed'); } 
 /* Reset */ ul { list-style-type: none; padding: 0; } /* Actual Notes */ .refine { width: 200px; border: 1px solid black; } .refine__heading { font-size: 20px; display: flex; justify-content: space-between; border-bottom: 1px solid #dadbd9; padding-left: 5px; padding-right: 5px; } .refine__content { overflow: hidden; transition: max-height 0.5s ease-out; height: auto; max-height: 100px; border-bottom: 1px solid #dadbd9; /* important */ } .refine label { display: flex; justify-content: space-between; padding-left: 5px; padding-right: 5px; } .collapsed { max-height: 0px; /* CHANGED FROM HERE DOWN */ border-bottom-width: 0; /* important */ transition-property: max-height, border-bottom-width; transition-duration: 0.3s; transition-delay: 0, 2s; transition-timing-function: ease-out; } 
 <link rel="stylesheet" type="text/css" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css"> <ul class="refine"> <li class="refine__section"> <div class="refine__heading"><span class="refine__heading-content">Vendors</span><i class="fas fa-caret-down"></i></div> <div class="refine__content"> <label><span class="refine__item">Nike</span><span class="count">4</span></label> <label><span class="refine__item">Adidas</span><span class="count">5</span></label> <label><span class="refine__item">Puma</span><span class="count">6</span></label> </div> </li> <li class="refine__section"> <div class="refine__heading"><span class="refine__heading-content">Shoe Size</span><i class="fas fa-caret-down"></i></div> <div class="refine__content"> <label><span class="refine__item">Large</span><span class="count">4</span></label> <label><span class="refine__item">Medium</span><span class="count">5</span></label> <label><span class="refine__item">Small</span><span class="count">6</span></label> </div> </li> </ul> 

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

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