css height为auto的transition过渡效果--max-height

手风琴效果,展开时根据内容自适应高度即从height: (any)px; 变化到 height: auto; 此时设置transition不会产生效果, 原因是 transition 无法将 ()px 变为不是具体数值的 auto

解决方法:

设置max-height,max-height尽可能最大,transition也要设置max-height;
我一开始写的height,一直没有效果。

<div @click.stop="getmorerule()">更多规则</div>
<div class="rulelist">
    <div class="ruli" v-for="(vo,index) in 4" :key="index">
         <div>可免费使用包间</div>
     </div>
 </div>
getmorerule(){
    document.querySelector('.rulelist').style.cssText="height:auto;max-height:50vh;visibility:visible";
},
.rulelist{
	height: 0;visibility: hidden;max-height:0;
	transition: max-height .5s ease-in-out;
	-moz-transition: max-height .5s ease-in-out;	/* Firefox 4 */
	-webkit-transition: max-height .5s ease-in-out;	/* Safari 和 Chrome */
	-o-transition: max-height .5s ease-in-out;	/* Opera */
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
你可以使用Vue的`v-for`指令结合CSS来创建图片手风琴效果。下面是一个简单的示例: ```html <template> <div class="accordion"> <div class="accordion-item" v-for="(image, index) in images" :key="index"> <img :src="image.url" alt="Image"> <div class="content" :class="{ 'active': activeIndex === index }"> <p>{{ image.description }}</p> </div> </div> </div> </template> <script> export default { data() { return { images: [ { url: 'image1.jpg', description: 'Image 1 description' }, { url: 'image2.jpg', description: 'Image 2 description' }, // Add more images here ], activeIndex: null }; }, methods: { toggleAccordion(index) { this.activeIndex = (this.activeIndex === index) ? null : index; } } }; </script> <style> .accordion { display: flex; flex-wrap: wrap; } .accordion-item { flex: 1 0 33%; /* Adjust this value as per your layout */ position: relative; overflow: hidden; transition: flex-basis 0.3s ease; } .accordion-item img { width: 100%; } .content { background-color: #f1f1f1; padding: 10px; max-height: 0; overflow: hidden; transition: max-height 0.3s ease; } .content.active { max-height: 200px; /* Adjust this value as per your content */ } </style> ``` 在上面的示例中,我们使用`v-for`指令遍历`images`数组,并为每个图片创建一个手风琴项。点击手风琴项时,通过`toggleAccordion`方法切换`activeIndex`的值,以展开或折叠内容部分。CSS样式定义了手风琴的布局和过渡效果。 请确保将`image1.jpg`和`image2.jpg`替换为你自己的图片路径,并根据需要调整样式。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值