• 小程序使用uni.createAnimation只执行一次的问题


    思路:
    1. 在页面创建的时候,创建一个临时动画对象
    2. 调用 step() 来表示一组动画完成
    3. 通过动画实例的export方法导出动画数据传递给组件的animation属性
    4. 还原动画
    5. 页面卸载的时候,清除动画数据
    1. <script>
    2. export default {
    3. data() {
    4. return {
    5. list:[
    6. {id:"001",memo:"苹果"},
    7. {id:"002",memo:"橘子"},
    8. {id:"003",memo:"草莓"},
    9. {id:"004",memo:"香蕉"}
    10. ],
    11. animationData: {},
    12. animationDataArr: []
    13. };
    14. },
    15. onLoad() {
    16. // 1 在页面创建的时候,创建一个临时动画对象
    17. this.animation = uni.createAnimation();
    18. this.animationDataArr=Array(this.list.length).fill({});
    19. },
    20. onUnload() {
    21. // 5 页面卸载的时候,清除动画数据
    22. this.animationData = {};
    23. this.animationDataArr=Array(this.list.length).fill({});
    24. },
    25. methods: {
    26. // 实现点赞动画效果
    27. praiseMe(index) {
    28. // 2 调用 step() 来表示一组动画完成
    29. this.animation.translateY(-90).opacity(1).step({
    30. duration: 400
    31. });
    32. // 3 通过动画实例的export方法导出动画数据传递给组件的animation属性
    33. this.animationData = this.animation;
    34. this.animationDataArr[index] = this.animationData.export();
    35. // 4 还原动画
    36. setTimeout(()=> {
    37. this.animation.translateY(0).opacity(0).step({
    38. duration: 0
    39. });
    40. this.animationData = this.animation;
    41. this.animationDataArr[index] = this.animationData.export();
    42. }, 600)
    43. },
    44. }
    45. };
    46. script>
    47. <style scoped>
    48. .item{
    49. display: flex;
    50. align-items: center;
    51. text-align: center;
    52. border: 1px pink solid;
    53. margin-top:20rpx ;
    54. padding: 20rpx 0;
    55. }
    56. .item image{
    57. width: 80rpx;
    58. height: 80rpx;
    59. z-index: 10;
    60. }
    61. .item .left{
    62. flex: 1;
    63. }
    64. .item .right{
    65. width: 300rpx;
    66. border-left: 1px pink dashed;
    67. padding-top: 50rpx;
    68. }
    69. .praise-me {
    70. font-size: 14px;
    71. color: #feab2a;
    72. }
    73. .animation-opacity {
    74. font-weight: bold;
    75. opacity: 0;
    76. }
    77. style>

     

  • 相关阅读:
    【文档+源码+调试讲解】国风彩妆网站springboot
    离线 notepad++ 添加到右键菜单
    python之print
    高纬度矩阵乘法的意义
    Web前后端漏洞分析与防御
    京东小程序平台助力快送实现跨端
    15——go语言中的流程控制
    高等教育心理学:教师职业心理(完) 不是特别重要
    Qt 场景(QGraphicsScene)自绘可自由变换与移动的图元(QGraphicsObject)
    ES6介绍
  • 原文地址:https://blog.csdn.net/qq_40999917/article/details/133796318