index.html 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. <script src="../../dist/vue.js"></script>
  33. </head>
  34. <body>
  35. <div id="el">
  36. <button @click="insert">insert at random index</button>
  37. <button @click="reset">reset</button>
  38. <button @click="shuffle">shuffle</button>
  39. <transition-group tag="ul" name="fade" class="container">
  40. <item v-for="item in items"
  41. class="item"
  42. :msg="item"
  43. :key="item"
  44. @rm="remove(item)">
  45. </item>
  46. </transition-group>
  47. </div>
  48. <script>
  49. var items = [1, 2, 3, 4, 5]
  50. var id = items.length + 1
  51. var vm = new Vue({
  52. el: '#el',
  53. data: {
  54. items: items
  55. },
  56. components: {
  57. item: {
  58. props: ['msg'],
  59. template: `<div>{{ msg }} <button @click="$emit('rm')">x</button></div>`
  60. }
  61. },
  62. methods: {
  63. insert () {
  64. var i = Math.round(Math.random() * this.items.length)
  65. this.items.splice(i, 0, id++)
  66. },
  67. reset () {
  68. this.items = [1, 2, 3, 4, 5]
  69. },
  70. shuffle () {
  71. this.items = _.shuffle(this.items)
  72. },
  73. remove (item) {
  74. var i = this.items.indexOf(item)
  75. if (i > -1) {
  76. this.items.splice(i, 1)
  77. }
  78. }
  79. }
  80. })
  81. </script>
  82. </body>
  83. </html>