vue过渡

2017-04-03  本文已影响20人  寒梁沐月

常用自定义动画

    <style>
        #div1{
            width:100px;
            height:100px;
            background: red;
        }

        .fade-transition{
            transition: 1s all ease;    
        }
        .fade-enter{
            opacity: 0;
        }
        .fade-leave{
            opacity: 0;
            transform: translateX(200px);
        }
    </style>
</head>
<body>
    <div id="box">
        <input type="button" value="按钮" @click="toggle">
        <div id="div1" v-show="bSign" transition="fade"></div>
    </div>

    <script>
        new Vue({
            el:'#box',
            data:{
                bSign:true
            },
            methods:{
                /*toggle:function(){
                    alert(1);
                }*/
                toggle(){
                    this.bSign=!this.bSign;
                }
            }
        });
    </script>
</body>

外部引用animation

<link rel="stylesheet" href="bower_components/animate.css/animate.css">
<style>
  #box{
    width:400px;
    margin: 0 auto;
  }
  #div1{
    width:100px;
    height:100px;
    background: red;
  }
</style>
</head>
<body>
<div id="box">
  <input type="button" value="按钮" @click="toggle">
  <div id="div1" class="animated" v-show="bSign" transition="bounce"></div>
</div>

<script>
  new Vue({
    el:'#box',
    data:{
      bSign:true
    },
    methods:{
      toggle(){
        this.bSign=!this.bSign;
      }
    },
    transitions:{ //定义所有动画名称
      bounce:{
        enterClass:'zoomInLeft',
        leaveClass:'zoomOutRight'
      }
    }
  });
</script>
</body>

上一篇 下一篇

猜你喜欢

热点阅读