有你在真好 的个人博客
vue-10 动画效果案例
阅读:2186 添加日期:2021/3/27 23:16:00 原文链接:https://www.toutiao.com/item/6935797946810139150/
  • CSS 动画用法同 CSS 过渡,只不过采用 animation 为指定动画效果
  • 功能实现:

点击按钮后, 文本内容有放大缩小效果

在 vue-02-过渡&动画和指令 目录下创建 02-动画效果.html

注意:官网上面源码有问题,要在 <p> 元素上增加样式 style="display: inline-block"

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /*显示过程中的动画效果*/
        .cyz-enter-active {
            animation: bounce-in 1s;
            /*bounce-in引用了下面@keyframes中定义的持续3秒*/
        }

        /*隐藏过程中的动画效果*/
        .cyz-leave-active {
            animation: bounce-in 3s reverse;
            /*reverse 相反的顺序*/
        }

        @keyframes bounce-in {
            0% {
                /*持续时长的百分比,如持续1s,0%表示当0秒,50%表示当0.5秒,100%表示当1秒*/
                transform: scale(0);
                /*缩小为0*/
            }

            50% {
                transform: scale(1.5);
                /*放大1.5倍*/
            }

            100% {
                transform: scale(1);
                /*原始大小*/
            }
        }
    </style>
</head>

<body>
    <div id="demo">
        <button @click="show = !show">放大缩小动画</button>
        <br>
        <transition name="cyz">
            <p v-show="show" style="display: inline-block;">菜园子,陪你学习,伴你成长!</p>
        </transition>

    </div>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script>
        new Vue({
            el: '#demo',
            data: {
                show: true
            }
        })
    </script>
</body>

</html>

git源码地址:
https://gitee.com/cyzgw/vue_demo.git

ICP备案号:苏ICP备14035786号-1 苏公网安备 32050502001014号