• VUE实例课程---5、vue网格动画


    VUE实例课程---5、vue网格动画

    一、总结

    一句话总结:

    vue网格动画可以用<transition-group> 组件、v-move属性、lodash.js来做。 原理就是对元素移动的先后位置加动画。

    <transition-group> 组件还有一个特殊之处。不仅可以进入和离开动画,还可以改变定位。要使用这个新功能只需了解新增的 v-move attribute,它会在元素的改变定位的过程中应用。像之前的类名一样,可以通过 name 属性来自定义前缀,也可以通过 move-class 属性手动设置。

    <style>
      .cell-move {
          transition: transform 1s;
      }
    </style>
    
    <div id="sudoku-demo" class="demo">
        <button @click="shuffle">
            Shuffle
        </button>
        <transition-group name="cell" tag="div" class="container">
            <div v-for="cell in cells" :key="cell.id" class="cell">
                {{ cell.number }}
            </div>
        </transition-group>
    </div>
    
    <script>
        new Vue({
            el: "#sudoku-demo",
            data: {
                cells: Array.apply(null, { length: 81 }).map(function(_, index) {
                    return {
                        id: index,
                        number: (index % 9) + 1
                    };
                })
            },
            methods: {
                shuffle: function() {
                    this.cells = _.shuffle(this.cells);
                }
            }
        });
    </script>

    二、vue网格动画

    博客对应课程的视频位置:

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4     <title>List Move Transitions Sudoku Example</title>
     5     <script src="https://unpkg.com/vue"></script>
     6     <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.14.1/lodash.min.js"></script>
     7     <style>
     8         .container {
     9             display: flex;
    10             flex-wrap: wrap;
    11             width: 238px;
    12             margin-top: 10px;
    13         }
    14         .cell {
    15             display: flex;
    16             justify-content: space-around;
    17             align-items: center;
    18             width: 25px;
    19             height: 25px;
    20             border: 1px solid #aaa;
    21             margin-right: -1px;
    22             margin-bottom: -1px;
    23         }
    24         .cell:nth-child(3n) {
    25             margin-right: 0;
    26         }
    27         .cell:nth-child(27n) {
    28             margin-bottom: 0;
    29         }
    30         .cell-move {
    31             transition: transform 1s;
    32         }
    33     </style>
    34 </head>
    35 <body>
    36 <!--
    37 
    38 
    39 vue网格动画可以用<transition-group> 组件、v-move属性、lodash.js来做。 原理就是对元素移动的先后位置加动画。
    40 
    41 <transition-group> 组件还有一个特殊之处。不仅可以进入和离开动画,还可以改变定位。要使用这个新功能只需了解新增的 v-move attribute,它会在元素的改变定位的过程中应用。像之前的类名一样,可以通过 name 属性来自定义前缀,也可以通过 move-class 属性手动设置。
    42 
    43 -->
    44 <div id="sudoku-demo" class="demo">
    45     <h1>Lazy Sudoku</h1>
    46     <p>Keep hitting the shuffle button until you win.</p>
    47 
    48     <button @click="shuffle">
    49         Shuffle
    50     </button>
    51     <transition-group name="cell" tag="div" class="container">
    52         <div v-for="cell in cells" :key="cell.id" class="cell">
    53             {{ cell.number }}
    54         </div>
    55     </transition-group>
    56 </div>
    57 
    58 <script>
    59     new Vue({
    60         el: "#sudoku-demo",
    61         data: {
    62             cells: Array.apply(null, { length: 81 }).map(function(_, index) {
    63                 return {
    64                     id: index,
    65                     number: (index % 9) + 1
    66                 };
    67             })
    68         },
    69         methods: {
    70             shuffle: function() {
    71                 this.cells = _.shuffle(this.cells);
    72             }
    73         }
    74     });
    75 </script>
    76 </body>
    77 </html>

     
  • 相关阅读:
    求相同号码一天内的上网流量——mapreduce
    scala初学
    对web日志文件实现按照人员、行为分类
    08 ROS阶段总结——package.xml 和 CMakeLists.txt 详细解读
    06 ROS中的节点、话题和服务
    07 ROS 的常见消息类型
    01 ROS下的三维点云数据处理(一)点云数据来源
    01 Opencv系列(一)ROS和opencv图像数据的转换
    01 ROS的运行架构——环境变量和工作空间
    02 Opencv系列(二)ROS框架下的摄像头调用方法
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/12749392.html
Copyright © 2020-2023  润新知