当前位置:首页 > VUE

vue 实现jqslidedown

2026-03-27 08:20:55VUE

Vue 实现 jQuery slideDown 效果

在 Vue 中实现类似 jQuery 的 slideDown 动画效果,可以通过 Vue 的过渡系统或 CSS 动画来实现。以下是几种常见的方法:

使用 Vue Transition 组件

Vue 提供了 <transition> 组件,可以方便地实现元素的显示和隐藏动画。

<template>
  <div>
    <button @click="toggle">Toggle</button>
    <transition name="slide">
      <div v-if="isVisible" class="content">
        This content will slide down and up.
      </div>
    </transition>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isVisible: false
    };
  },
  methods: {
    toggle() {
      this.isVisible = !this.isVisible;
    }
  }
};
</script>

<style>
.slide-enter-active, .slide-leave-active {
  transition: max-height 0.5s ease;
  overflow: hidden;
}

.slide-enter, .slide-leave-to {
  max-height: 0;
}

.slide-enter-to, .slide-leave {
  max-height: 1000px; /* 设置一个足够大的值 */
}

.content {
  background: #f0f0f0;
  padding: 10px;
  margin-top: 10px;
}
</style>

使用 CSS Animation

通过 CSS 的 @keyframes 也可以实现类似的滑动效果。

<template>
  <div>
    <button @click="toggle">Toggle</button>
    <div v-if="isVisible" class="slide-down">
      This content will slide down.
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isVisible: false
    };
  },
  methods: {
    toggle() {
      this.isVisible = !this.isVisible;
    }
  }
};
</script>

<style>
.slide-down {
  animation: slideDown 0.5s ease forwards;
  overflow: hidden;
}

@keyframes slideDown {
  from {
    max-height: 0;
    opacity: 0;
  }
  to {
    max-height: 1000px;
    opacity: 1;
  }
}
</style>

使用第三方库

如果需要更复杂的动画效果,可以考虑使用第三方动画库,如 animate.cssvue-animate

  1. 安装 animate.css

    npm install animate.css
  2. 在 Vue 中使用:

    vue 实现jqslidedown

    <template>
      <div>
        <button @click="toggle">Toggle</button>
        <transition
          enter-active-class="animate__animated animate__slideInDown"
          leave-active-class="animate__animated animate__slideOutUp"
        >
          <div v-if="isVisible" class="content">
            This content will slide down with animate.css.
          </div>
        </transition>
      </div>
    </template>
    
    <script>
    import 'animate.css';
    export default {
      data() {
        return {
          isVisible: false
        };
      },
      methods: {
        toggle() {
          this.isVisible = !this.isVisible;
        }
      }
    };
    </script>
    
    <style>
    .content {
      background: #f0f0f0;
      padding: 10px;
      margin-top: 10px;
    }
    </style>

注意事项

  • 使用 max-height 时,需要设置一个足够大的值以确保内容完全展开。
  • 动画的平滑度可以通过调整 transitionanimation 的时间函数(如 easeease-in-out)来优化。
  • 如果需要更精确的控制,可以考虑使用 JavaScript 钩子(如 @enter@leave)结合 requestAnimationFrame 实现自定义动画逻辑。

标签: vuejqslidedown
分享给朋友:

相关文章

vue 实现拖拽

vue 实现拖拽

Vue 实现拖拽功能 使用 HTML5 原生拖拽 API HTML5 提供了原生的拖拽 API,可以通过 draggable 属性和相关事件实现拖拽功能。 <template> &l…

vue实现active

vue实现active

Vue 实现 active 状态的方法 在 Vue 中实现 active 状态可以通过以下几种方式实现,具体取决于使用场景和需求。 使用 v-bind:class 动态绑定类名 通过 v-bind:…

vue实现换肤

vue实现换肤

使用 CSS 变量实现换肤 在 Vue 项目中,可以通过 CSS 变量(Custom Properties)动态切换主题色。CSS 变量可以在运行时修改,适合实现换肤功能。 定义全局 CSS 变量:…

vue实现slot

vue实现slot

Vue 中的 Slot 实现方法 Vue 的 slot 是一种内容分发机制,允许父组件向子组件插入内容。以下是几种常见的 Slot 实现方式: 默认 Slot 子组件通过 <slot>…

vue实现分步

vue实现分步

Vue 实现分步功能 在 Vue 中实现分步功能可以通过多种方式完成,以下是几种常见的方法: 使用动态组件 通过动态组件切换不同的步骤内容,结合 v-if 或 component 标签实现分步逻辑。…

vue模版实现

vue模版实现

Vue 模板实现方法 Vue 模板是 Vue.js 的核心特性之一,用于声明式地将 DOM 绑定至底层 Vue 实例的数据。以下是几种常见的 Vue 模板实现方式: 单文件组件(SFC) 使用 .v…