Coder Social home page Coder Social logo

vue-slide-up-down's Introduction

vue-slide-up-down

Like jQuery's slideUp / slideDown, but for Vue!

Demo: https://codepen.io/danieldiekmeier/pen/YapGWq

Installation

npm i vue-slide-up-down

Usage with Webpack or other module bundlers:

import SlideUpDown from 'vue-slide-up-down'
// or
const SlideUpDown = require('vue-slide-up-down')

Vue.component('slide-up-down', SlideUpDown)

Or use the UMD build directly in your browser (the component is provided as window.VueSlideUpDown).

<script type="text/javascript" src="node_modules/vuejs/dist/vue.min.js"></script>
<script type="text/javascript" src="node_modules/vue-slide-up-down/dist/vue-slide-up-down.umd.js"></script>
<script type="text/javascript">
  Vue.component('slide-up-down', VueSlideUpDown);
</script>

Usage

The component takes three props:

  • active (Boolean): Whether to show the component (true) or not (false)
  • duration (Number): How long the animation is supposed to be, in milliseconds. Defaults to 500.
  • tag (String): Which HTML tag to use for the wrapper element. Defaults to div.
<div class="MyContent">
  <h1>Always show this</h1>

  <slide-up-down :active="active" :duration="1000">
    Only show this if "active” is true
  </slide-up-down>
</div>

Trigger a (re-)layout

If you need to trigger a relayout (for example if your content changed), you can call the .layout() method on your slide-up-down instance:

<slide-up-down ref="upDown">{{ myContent }}</slide-up-down>

And in your parent component:

watch: {
  myContent () {
    this.$refs.upDown.layout()
  }
}

Custom transition-timing-function

If you want to use a different timing function, add some CSS for your <slide-up-down> element. (See demo/index.html for a full example.)

<style>
  .wobbly-accordeon {
    transition-timing-function: cubic-bezier(0.195, 1.650, 0.435, -0.600);
  }
</style>

<slide-up-down class="wobbly-accordeon">
  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Soluta omnis velit ab culpa, officia, unde nesciunt temporibus cum reiciendis distinctio.
</slide-up-down>

Listening for Events

To keep the codebase small, but powerful™, this package doesn't provide hooks for transitionend, transitionstart or other events, but instead provides direct access to the DOM Element that does the actual sliding up and down:

Add a ref to your SlideUpDown-Element:

<slide-up-down ref="upDown">My Content</slide-up-down>

And add the event listener you want:

mounted () {
  const el = this.$refs.upDown.el
  el.addEventListener('transitionend', () => {
    console.log('transition ended')
  })
}

vue-slide-up-down's People

Contributors

danieldiekmeier avatar sailorsteve avatar

Watchers

Manfred Wuits avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.