zoukankan      html  css  js  c++  java
  • vue.js实现div展开收起动画

    const elTransition = '0.3s height ease-in-out, 0.3s padding-top ease-in-out, 0.3s padding-bottom ease-in-out'
    const Transition = {
      'before-enter' (el) {
        el.style.transition = elTransition
        if (!el.dataset) el.dataset = {}
    
        el.dataset.oldPaddingTop = el.style.paddingTop
        el.dataset.oldPaddingBottom = el.style.paddingBottom
    
        el.style.height = 0
        el.style.paddingTop = 0
        el.style.paddingBottom = 0
      },
    
      'enter' (el) {
        el.dataset.oldOverflow = el.style.overflow
        if (el.scrollHeight !== 0) {
          el.style.height = el.scrollHeight + 'px'
          el.style.paddingTop = el.dataset.oldPaddingTop
          el.style.paddingBottom = el.dataset.oldPaddingBottom
        } else {
          el.style.height = ''
          el.style.paddingTop = el.dataset.oldPaddingTop
          el.style.paddingBottom = el.dataset.oldPaddingBottom
        }
    
        el.style.overflow = 'hidden'
      },
    
      'after-enter' (el) {
        el.style.transition = ''
        el.style.height = ''
        el.style.overflow = el.dataset.oldOverflow
      },
    
      'before-leave' (el) {
        if (!el.dataset) el.dataset = {}
        el.dataset.oldPaddingTop = el.style.paddingTop
        el.dataset.oldPaddingBottom = el.style.paddingBottom
        el.dataset.oldOverflow = el.style.overflow
    
        el.style.height = el.scrollHeight + 'px'
        el.style.overflow = 'hidden'
      },
    
      'leave' (el) {
        if (el.scrollHeight !== 0) {
          el.style.transition = elTransition
          el.style.height = 0
          el.style.paddingTop = 0
          el.style.paddingBottom = 0
        }
      },
    
      'after-leave' (el) {
        el.style.transition = ''
        el.style.height = ''
        el.style.overflow = el.dataset.oldOverflow
        el.style.paddingTop = el.dataset.oldPaddingTop
        el.style.paddingBottom = el.dataset.oldPaddingBottom
      }
    }
    
    export default {
      name: 'collapseTransition',
      functional: true,
      render (h, { children }) {
        const data = {
          on: Transition
        }
        return h('transition', data, children)
      }
    }

    1.建个JS文件随便取个名字,把上面的js复制进去,

    2.在你要用的页面 import 组件名字(随便取) from '你建的JS文件路径',

    3.export default{components:{组件名字}},

    4.data添加isActive=true;

    5.在需要使用的地方

    <组件名称>
     <div class="collapse-wrap"
       v-show="isActive">
      <!-- @slot default -->
      <slot></slot>
    </div> 
    </组件名称>
    
    <标签 @click="isActive=!isActive">打开或者收缩</标签>
    

    https://segmentfault.com/u/sinianjun斯年君

    https://segmentfault.com/q/1010000011359250 的回答

  • 相关阅读:
    Java中关于时间日期格式保存到mysql的问题
    传输json数据到前台的时候,数据中包含日期数据
    字符串的分隔方法 split()
    实体类中用基本类型好,还是用包装类型
    Android中的task和stack
    在res文件下新建文件夹
    Android活动和碎片的生命周期及addToBackStack()方法
    draw9patch图片拉伸
    Android studio新建文件出现setContentView(R.layout.activity_main);中的R标红错误解决方法
    listview控件的使用
  • 原文地址:https://www.cnblogs.com/aknife/p/12504243.html
Copyright © 2011-2022 走看看