vue动画

举报
小米粒-biubiubiu 发表于 2020/12/04 00:55:47 2020/12/04
【摘要】                                                         vue动画 一、vue中css 的动画原理     <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>fade出入动画</title> <script src="https://...

                                                        vue动画

一、vue中css 的动画原理

 

 


  
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>fade出入动画</title>
  6. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  7. <style type="text/css">
  8. .fade-enter{
  9. opacity: 0;
  10. }
  11. .fade-enter-active{
  12. transition:opacity 3s;
  13. }
  14. .fade-leave-to{
  15. opacity: 0;
  16. }
  17. .fade-leave-active{
  18. transition: opacity 3s;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div id="app">
  24. <transition name="fade">
  25. <div v-show="show">hello world</div>
  26. </transition>
  27. <button @click="handleClick">切换</button>
  28. </div>
  29. <script type="text/javascript">
  30. var app = new Vue({
  31. el:"#app",
  32. data:{
  33. show:true
  34. },
  35. methods:{
  36. handleClick: function () {
  37. this.show = !this.show;
  38. }
  39. }
  40. });
  41. </script>
  42. </body>
  43. </html>

 

二、使用animate.css库


  
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>使用animate.css库</title>
  6. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  7. <link rel="stylesheet" href="../animate.css" />
  8. <style type="text/css">
  9. /*@keyframes bounce-in {
  10. 0% {
  11. transform: scale(0);
  12. }
  13. 50% {
  14. transform: scale(1.5);
  15. }
  16. 100% {
  17. transform: scale(1);
  18. }
  19. }
  20. .fade-enter-active {
  21. transform-origin: left center;
  22. animation: bounce-in 1s;
  23. }
  24. .fade-leave-active {
  25. transform-origin: left center;
  26. animation: bounce-in 1s reverse;
  27. }*/
  28. /*.enter{
  29. transform-origin: left center;
  30. animation: bounce-in 1s;
  31. }
  32. .leave{
  33. transform-origin: left center;
  34. animation: bounce-in 1s reverse;
  35. }*/
  36. </style>
  37. </head>
  38. <body>
  39. <div id="app">
  40. <!--自定义动画enter 和 leave 的 class名称-->
  41. <!--使用animate.css库-->
  42. <transition name="fade" enter-active-class="animated swing" leave-active-class="animated shake">
  43. <div v-show="show">hello world</div>
  44. </transition>
  45. <button @click="handleClick">切换</button>
  46. </div>
  47. <script type="text/javascript">
  48. var app = new Vue({
  49. el: "#app",
  50. data: {
  51. show: true
  52. },
  53. methods: {
  54. handleClick: function() {
  55. this.show = !this.show;
  56. }
  57. }
  58. });
  59. </script>
  60. </body>
  61. </html>

  
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>使用animate.css库</title>
  6. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  7. <link rel="stylesheet" href="../animate.css" />
  8. <style type="text/css">
  9. .fade-enter{
  10. opacity: 0;
  11. }
  12. .fade-enter-active {
  13. transition: opacity 3s;
  14. }
  15. .fade-leave-to{
  16. opacity: 0;
  17. }
  18. .fade-leave-active {
  19. transition: opacity 3s;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <div id="app">
  25. <!--自定义动画enter 和 leave 的 class名称-->
  26. <!--使用animate.css库-->
  27. <transition name="fade"
  28. type="transition"
  29. :duration="{enter:5000,leave:10000}"
  30. appear
  31. enter-active-class="animated swing fade-enter-active"
  32. leave-active-class="animated shake fade-leave-active"
  33. appear-active-class="animated swing">
  34. <div v-show="show">hello world</div>
  35. </transition>
  36. <button @click="handleClick">切换</button>
  37. </div>
  38. <script type="text/javascript">
  39. var app = new Vue({
  40. el: "#app",
  41. data: {
  42. show: true
  43. },
  44. methods: {
  45. handleClick: function() {
  46. this.show = !this.show;
  47. }
  48. }
  49. });
  50. </script>
  51. </body>
  52. </html>

三 、vue 中的js动画 与 velocity.js 动画库


  
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>vue中的js动画 与 velocity.js</title>
  6. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  7. <script src="https://cdn.bootcss.com/velocity/2.0.5/velocity.js"></script>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <!--
  12. 作者:offline
  13. 时间:2019-03-24
  14. 描述:transition 的 几个监听钩子函数
  15. @before-enter
  16. @enter
  17. @after-enter
  18. @before-leave
  19. @leave
  20. @after-leave
  21. -->
  22. <transition name="fade" @before-enter="handleBeforeEnter" @enter="handleEnter" @after-enter="handleAfterEnter">
  23. <div v-show="show">hello world</div>
  24. </transition>
  25. <button @click="handleClick">切换</button>
  26. </div>
  27. <script type="text/javascript">
  28. var app = new Vue({
  29. el: "#app",
  30. data: {
  31. show: true
  32. },
  33. methods: {
  34. handleClick: function() {
  35. this.show = !this.show;
  36. },
  37. handleBeforeEnter: function(el) {
  38. //el.style.color = "red";
  39. el.style.opacity = 0;
  40. },
  41. handleEnter: function(el, done) {
  42. // setTimeout(() => {
  43. // el.style.color = 'green';
  44. // }, 2000);
  45. // setTimeout(() => {
  46. // done();
  47. // }, 4000)
  48. Velocity(el,{opacity:1},{duration:1000,complete:done})
  49. },
  50. handleAfterEnter: function(el) {
  51. //el.style.color = 'black'
  52. alert("动画结束")
  53. }
  54. }
  55. });
  56. </script>
  57. </body>
  58. </html>

 四、vue中多元素或组件的过渡,vue中列表的过渡 以及动画通过组件的形式封装


  
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>vue中多元素或组件的过渡,vue中列表的过渡 以及动画通过组件的形式封装</title>
  6. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  7. <script src="https://cdn.bootcss.com/velocity/2.0.5/velocity.js"></script>
  8. <style type="text/css">
  9. .v-enter,
  10. .v-leave-to {
  11. opacity: 0;
  12. }
  13. .v-enter-active,
  14. .v-leave-active {
  15. transition: opacity 1s;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <div id="app">
  21. <!--
  22. 作者:offline
  23. 时间:2019-03-24
  24. 描述:transition 的 几个监听钩子函数
  25. @before-enter
  26. @enter
  27. @after-enter
  28. @before-leave
  29. @leave
  30. @after-leave
  31. -->
  32. <transition mode="in-out">
  33. <!--<div v-if="show" key="hello">hello world</div>
  34. <div v-else="show" key="bye">bye world</div>-->
  35. <child v-if="show"></child>
  36. <child-one v-else="show"></child-one>
  37. </transition>
  38. <button @click="handleClick">切换</button>
  39. <transition-group>
  40. <div v-for="(item,index) of list" :key="item.id">
  41. {{item}}
  42. </div>
  43. </transition-group>
  44. <button @click="handleBtnClick">Add</button>
  45. <fade :show="show">
  46. <div><h1>123</h1></div>
  47. </fade>
  48. <fade :show="show">
  49. <p>asjd金卡说不定卡比烧烤店把卡仕达卡仕达你阿兰埃里克森你打曼德拉上的
  50. 啊看到了看上的</p>
  51. </fade>
  52. </div>
  53. <script type="text/javascript">
  54. //定义组件
  55. Vue.component("child", {
  56. template: "<div>child</div>"
  57. });
  58. Vue.component("child-one", {
  59. template: "<div>child-one</div>"
  60. });
  61. Vue.component("fade",{
  62. props:['show'],
  63. template:`<transition
  64. @before-enter="handleBeforeEnter"
  65. @enter="handleEnter" @after-enter="handleAfterEnter">
  66. <slot v-if="show"></slot>
  67. </transition>`,
  68. methods:{
  69. handleBeforeEnter: function(el) {
  70. //el.style.color = "red";
  71. //el.style.opacity = 0;
  72. },
  73. handleEnter: function(el, done) {
  74. setTimeout(() => {
  75. el.style.color = 'orange';
  76. }, 2000);
  77. setTimeout(() => {
  78. done();
  79. }, 4000)
  80. // Velocity(el,{opacity:1},{duration:1000,complete:done})
  81. },
  82. handleAfterEnter: function(el) {
  83. el.style.color = 'black'
  84. //alert("动画结束")
  85. }
  86. }
  87. });
  88. var count = 0;
  89. var app = new Vue({
  90. el: "#app",
  91. data: {
  92. show: true,
  93. list: []
  94. },
  95. methods: {
  96. handleClick: function() {
  97. this.show = !this.show;
  98. },
  99. handleBtnClick:function () {
  100. this.list.push({
  101. id:count++,
  102. title:"hello world"
  103. })
  104. }
  105. }
  106. });
  107. </script>
  108. </body>
  109. </html>

 

 

 

文章来源: blog.csdn.net,作者:血煞风雨城2018,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/qq_31905135/article/details/88779947

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。