index.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Move Animations</title>
  6. <style>
  7. .container {
  8. position: relative;
  9. padding: 0;
  10. }
  11. .item {
  12. width: 100%;
  13. height: 30px;
  14. background-color: #f3f3f3;
  15. border: 1px solid #666;
  16. box-sizing: border-box;
  17. }
  18. /* 1. declare transition */
  19. .fade-move,
  20. .fade-enter-active,
  21. .fade-leave-active {
  22. transition: all 0.5s cubic-bezier(0.55, 0, 0.1, 1);
  23. }
  24. /* 2. declare enter from and leave to state */
  25. .fade-enter,
  26. .fade-leave-to {
  27. opacity: 0;
  28. transform: scaleY(0.01) translate(30px, 0);
  29. }
  30. /* 3. ensure leaving items are taken out of layout flow so that moving
  31. animations can be calculated correctly. */
  32. .fade-leave-active {
  33. position: absolute;
  34. }
  35. </style>
  36. <script src="../../../node_modules/lodash/lodash.min.js"></script>
  37. <!-- Delete ".min" for console warnings in development -->
  38. <script src="../../../dist/vue.min.js"></script>
  39. </head>
  40. <body>
  41. <div id="el">
  42. <button @click="insert">insert at random index</button>
  43. <button @click="reset">reset</button>
  44. <button @click="shuffle">shuffle</button>
  45. <transition-group tag="ul" name="fade" class="container">
  46. <item
  47. v-for="item in items"
  48. class="item"
  49. :msg="item"
  50. :key="item"
  51. @rm="remove(item)"
  52. >
  53. </item>
  54. </transition-group>
  55. </div>
  56. <script>
  57. var items = [1, 2, 3, 4, 5]
  58. var id = items.length + 1
  59. var vm = new Vue({
  60. el: '#el',
  61. data: {
  62. items: items
  63. },
  64. components: {
  65. item: {
  66. props: ['msg'],
  67. template: `<div>{{ msg }} <button @click="$emit('rm')">x</button></div>`
  68. }
  69. },
  70. methods: {
  71. insert() {
  72. var i = Math.round(Math.random() * this.items.length)
  73. this.items.splice(i, 0, id++)
  74. },
  75. reset() {
  76. this.items = [1, 2, 3, 4, 5]
  77. },
  78. shuffle() {
  79. this.items = _.shuffle(this.items)
  80. },
  81. remove(item) {
  82. var i = this.items.indexOf(item)
  83. if (i > -1) {
  84. this.items.splice(i, 1)
  85. }
  86. }
  87. }
  88. })
  89. </script>
  90. </body>
  91. </html>