index.html 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. .fade-move, .fade-enter-active, .fade-leave-active {
  19. transition: all .5s cubic-bezier(.55,0,.1,1);
  20. }
  21. .fade-enter {
  22. opacity: 0;
  23. transform: scaleY(0) translate(30px, 0);
  24. }
  25. .fade-leave-active {
  26. position: absolute;
  27. opacity: 0;
  28. transform: scaleY(0.01) translate(30px, 0);
  29. }
  30. </style>
  31. <script src="https://cdn.jsdelivr.net/lodash/4.3.0/lodash.min.js"></script>
  32. <!-- Delete ".min" for console warnings in development -->
  33. <script src="../../dist/vue.min.js"></script>
  34. </head>
  35. <body>
  36. <div id="el">
  37. <button @click="insert">insert at random index</button>
  38. <button @click="reset">reset</button>
  39. <button @click="shuffle">shuffle</button>
  40. <transition-group tag="ul" name="fade" class="container">
  41. <item v-for="item in items"
  42. class="item"
  43. :msg="item"
  44. :key="item"
  45. @rm="remove(item)">
  46. </item>
  47. </transition-group>
  48. </div>
  49. <script>
  50. var items = [1, 2, 3, 4, 5]
  51. var id = items.length + 1
  52. var vm = new Vue({
  53. el: '#el',
  54. data: {
  55. items: items
  56. },
  57. components: {
  58. item: {
  59. props: ['msg'],
  60. template: `<div>{{ msg }} <button @click="$emit('rm')">x</button></div>`
  61. }
  62. },
  63. methods: {
  64. insert () {
  65. var i = Math.round(Math.random() * this.items.length)
  66. this.items.splice(i, 0, id++)
  67. },
  68. reset () {
  69. this.items = [1, 2, 3, 4, 5]
  70. },
  71. shuffle () {
  72. this.items = _.shuffle(this.items)
  73. },
  74. remove (item) {
  75. var i = this.items.indexOf(item)
  76. if (i > -1) {
  77. this.items.splice(i, 1)
  78. }
  79. }
  80. }
  81. })
  82. </script>
  83. </body>
  84. </html>