File: index.html

package info (click to toggle)
vue.js 2.6.12%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,124 kB
  • sloc: javascript: 80,436; sh: 97; makefile: 7
file content (88 lines) | stat: -rw-r--r-- 2,409 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Move Animations</title>
    <style>
      .container {
        position: relative;
        padding: 0;
      }
      .item {
        width: 100%;
        height: 30px;
        background-color: #f3f3f3;
        border: 1px solid #666;
        box-sizing: border-box;
      }
      /* 1. declare transition */
      .fade-move, .fade-enter-active, .fade-leave-active {
        transition: all .5s cubic-bezier(.55,0,.1,1);
      }
      /* 2. declare enter from and leave to state */
      .fade-enter, .fade-leave-to {
        opacity: 0;
        transform: scaleY(0.01) translate(30px, 0);
      }
      /* 3. ensure leaving items are taken out of layout flow so that moving
            animations can be calculated correctly. */
      .fade-leave-active {
        position: absolute;
      }
    </style>
    <script src="https://cdn.jsdelivr.net/lodash/4.3.0/lodash.min.js"></script>
    <!-- Delete ".min" for console warnings in development -->
    <script src="/javascript/vue/vue.min.js"></script>
  </head>
  <body>
    <div id="el">
      <button @click="insert">insert at random index</button>
      <button @click="reset">reset</button>
      <button @click="shuffle">shuffle</button>
      <transition-group tag="ul" name="fade" class="container">
        <item v-for="item in items"
          class="item"
          :msg="item"
          :key="item"
          @rm="remove(item)">
        </item>
      </transition-group>
    </div>

    <script>
      var items = [1, 2, 3, 4, 5]
      var id = items.length + 1

      var vm = new Vue({
        el: '#el',
        data: {
          items: items
        },
        components: {
          item: {
            props: ['msg'],
            template: `<div>{{ msg }} <button @click="$emit('rm')">x</button></div>`
          }
        },
        methods: {
          insert () {
            var i = Math.round(Math.random() * this.items.length)
            this.items.splice(i, 0, id++)
          },
          reset () {
            this.items = [1, 2, 3, 4, 5]
          },
          shuffle () {
            this.items = _.shuffle(this.items)
          },
          remove (item) {
            var i = this.items.indexOf(item)
            if (i > -1) {
              this.items.splice(i, 1)
            }
          }
        }
      })
    </script>
  </body>
</html>