蔫吧枣干巴梨 發表於 2026-5-3 22:16:50

CSS点击切换或隐藏盒子的卷起、展开效果

<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202310/20231008165211113.png" /></p>
<div class="jb51code"><pre class="brush:css;">&lt;template&gt;
&lt;div class="main"&gt;
    &lt;el-button @click="onCllick"&gt;切换&lt;/el-button&gt;
    &lt;transition name="slideDown"&gt;
      &lt;div class="info" v-if="isShow"&gt;1111&lt;/div&gt;
    &lt;/transition&gt;
&lt;/div&gt;
&lt;/template&gt;
&lt;script lang="ts"&gt;
import { defineComponent, reactive, toRefs } from 'vue'
export default defineComponent({
name: 'login-account ',
components: {},
setup(props, { emit, slots, attrs }) {
    const state = reactive({
      isShow: false
    })
    const onCllick = () =&gt; {
      console.log('切换')
      state.isShow = !state.isShow
    }
    return {
      ...toRefs(state),
      onCllick
    }
}
})
&lt;/script&gt;
&lt;style lang="less"&gt;
.info {
width: 100px;
height: 400px;
background-color: skyblue;
margin: 0 auto;
}
.slideDown-enter-active,
.slideDown-leave-active {
transition: all 0.5s ease-in-out;
}
.slideDown-enter-from {
height: 0;
}
.slideDown-leave-to {
height: 0;
}
&lt;/style&gt;</pre></div>
頁: [1]
查看完整版本: CSS点击切换或隐藏盒子的卷起、展开效果