elementUI内置过渡动画的使用

官方文档

内置过渡动画

  • fade 淡入淡出
<template>
// 提供 el-fade-in-linear 和 el-fade-in 两种效果
// 1. 
<transition name="el-fade-in-linear">
 <div v-show="show" style="width: 400px; height: 400px; background-color: skyblue">匀速淡入淡出</div>
</transition>
</template>
<script>
    export default {
    data: () => ({
      show: true
    })
  }
</script>

// 2.
<transition name="el-fade-in">
 <div v-show="show" style="width: 400px; height: 400px; background-color: skyblue">淡入淡出</div>
</transition>
</template>
<script>
    export default {
    data: () => ({
      show: true
    })
  }
</script>
  • 缩放效果
<template>
// 提供 el-zoom-in-center,el-zoom-in-top 和 el-zoom-in-bottom 三种效果
// 1. 
<transition name="el-zoom-in-center">
 <div v-show="show" style="width: 400px; height: 400px; background-color: skyblue">向中间缩放</div>
</transition>
</template>
<script>
    export default {
    data: () => ({
      show: true
    })
  }
</script>

// 2.
<transition name="el-zoom-in-top">
 <div v-show="show" style="width: 400px; height: 400px; background-color: skyblue">向顶部缩放</div>
</transition>
</template>
<script>
    export default {
    data: () => ({
      show: true
    })
  }
</script>

// 3.
<transition name="el-zoom-in-bottom">
 <div v-show="show" style="width: 400px; height: 400px; background-color: skyblue">向底部缩放</div>
</transition>
</template>
<script>
    export default {
    data: () => ({
      show: true
    })
  }
</script>
  • collapse 展开折叠
<template>
// 提供 el-fade-in-linear 和 el-fade-in 两种效果
// 1. 
<transition name="el-fade-in-linear">
 <div v-show="show" style="width: 400px; height: 400px; background-color: skyblue">匀速淡入淡出</div>
</transition>
</template>
<script>
    export default {
    data: () => ({
      show: true
    })
  }
</script>

// 2.
<transition name="el-fade-in">
 <div v-show="show" style="width: 400px; height: 400px; background-color: skyblue">淡入淡出</div>
</transition>
</template>
<script>
    export default {
    data: () => ({
      show: true
    })
  }
</script>
  • collapse 展开折叠
<template>
// 使用 el-collapse-transition 组件实现折叠展开效果
  <el-collapse-transition>  
  		 <div v-show="show">
          <div style="width: 400px; height: 400px; background-color: skyblue">折叠面板 </div>
         </div>
  </el-collapse-transition>
</template>
<script>
    export default {
    data: () => ({
      show: true
    })
  }
</script>
  • 按需引入
// fade/zoom 
import 'element-ui/lib/theme-chalk/base.css'
// collapse 折叠面板 - 全局注册
// main.js
import CollapseTransition from 'element-ui/lib/transitions/collapse-transition';
import Vue from 'vue'

Vue.component(CollapseTransition.name, CollapseTransition)

// xxx.vue
<template>
  <CollapseTransition>  
  		 <div v-show="show">
          <div style="width: 400px; height: 400px; background-color: skyblue">折叠面板 </div>
         </div>
  </CollapseTransition>
</template>
<script>
    export default {
    data: () => ({
      show: true
    })
  }
</script>
// collapse 折叠面板 - 局部注册
// main.js
import CollapseTransition from 'element-ui/lib/transitions/collapse-transition';
import Vue from 'vue'

Vue.component(CollapseTransition.name, CollapseTransition)

// xxx.vue
<template>
  <CollapseTransition>  
  		 <div v-show="show">
          <div style="width: 400px; height: 400px; background-color: skyblue">折叠面板 </div>
         </div>
  </CollapseTransition>
</template>
<script>
import CollapseTransition from "element-ui/lib/transitions/collapse-transition";
export default {
    components: {
    CollapseTransition,
  },
    data: () => ({
      show: true
    })
  }
</script>
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
为了实现点击el-input出现el-popover,并且使el-popover始终出现在el-input下方,可以按照以下步骤进行操作: 1. 在el-input标签中添加ref属性,用于在JavaScript中引用该元素。 2. 在el-input标签中添加@click事件,用于在单击el-input时触发JavaScript函数。 3. 在JavaScript函数中,使用this.$refs获取el-input元素的位置信息,并计算出el-popover应该出现的位置。 4. 在el-popover标签中添加v-model属性,用于控制el-popover的显示和隐藏。 5. 在el-popover标签中添加popper-class属性,用于自定义el-popover的样式。 6. 在el-popover标签中添加transition属性,用于设置el-popover的过渡效果。 下面是一个示例代码,可以实现点击el-input出现el-popover,并且使el-popover始终出现在el-input下方: ```html <template> <div> <el-input ref="input" v-model="inputValue" placeholder="请输入内容" @click="showPopover"></el-input> <el-popover v-model="popoverVisible" popper-class="my-popover" transition="el-fade-in-linear"> <div>这是一个el-popover</div> </el-popover> </div> </template> <script> export default { data() { return { inputValue: '', popoverVisible: false } }, methods: { showPopover() { this.popoverVisible = true; this.$nextTick(() => { const inputRect = this.$refs.input.getBoundingClientRect(); const popoverRect = this.$refs.popover.$el.getBoundingClientRect(); const top = inputRect.top + inputRect.height; const left = inputRect.left + inputRect.width / 2 - popoverRect.width / 2; this.$refs.popover.$el.style.top = `${top}px`; this.$refs.popover.$el.style.left = `${left}px`; }); } } } </script> <style> .my-popover { background-color: #f0f0f0; color: #333; border: none; box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); } </style> ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值