当前位置:   article > 正文

微信小程序 按钮点击动态展开收起(开发记录)_微信小程序 - 实现文本展开与收起功能组件

微信小程序 - 实现文本展开与收起功能组件

wxml代码

  1. <view>
  2. <image src="/pages/icon/daikaifa.png" class="img-style" animation="{{animCollect}}" bindtap="collect"></image>
  3. <image src="/pages/icon/daikaifa.png" class="img-style" animation="{{animTranspond}}" bindtap="transpond"></image>
  4. <image src="/pages/icon/daikaifa.png" class="img-style" animation="{{animInput}}" bindtap="input"></image>
  5. <image src="/pages/icon/add.png" class="img-plus-style" animation="{{animPlus}}" catchtap="moreBtn"></image>
  6. </view>

wxss代码

  1. .img-plus-style {
  2. height: 100rpx;
  3. width: 100rpx;
  4. position: fixed;
  5. bottom: 4%;
  6. right: 5%;
  7. z-index: 100;
  8. }
  9. .img-style {
  10. height: 120rpx;
  11. width: 120rpx;
  12. position: fixed;
  13. bottom: 4%;
  14. right: 5%;
  15. opacity: 0;
  16. }

js代码

  1. moreBtn: function () {
  2. this.plus();
  3. },
  4. //点击弹出
  5. plus: function () {
  6. if (!this.data.isPopping) {
  7. //弹出
  8. this.popp();
  9. this.setData({
  10. isPopping: true
  11. })
  12. }
  13. else {
  14. //缩回
  15. this.takeback();
  16. this.setData({
  17. isPopping: false
  18. });
  19. // console.log("弹出")
  20. }
  21. },
  22. input: function () {
  23. console.log("input")
  24. },
  25. transpond: function () {
  26. console.log("transpond")
  27. },
  28. collect: function () {
  29. console.log("transpond")
  30. },
  31. //弹出动画
  32. popp: function () {
  33. //plus顺时针旋转
  34. let animationPlus = wx.createAnimation({
  35. duration: 500,
  36. timingFunction: 'ease'
  37. })
  38. let animationcollect = wx.createAnimation({
  39. duration: 500,
  40. timingFunction: 'ease'
  41. })
  42. let animationTranspond = wx.createAnimation({
  43. duration: 500,
  44. timingFunction: 'ease'
  45. })
  46. let animationInput = wx.createAnimation({
  47. duration: 500,
  48. timingFunction: 'ease'
  49. })
  50. animationPlus.rotateZ(180).step();
  51. animationcollect.translate(-0, -100).rotateZ(0).opacity(1).step();
  52. animationTranspond.translate(-85, -75).rotateZ(0).opacity(1).step();
  53. animationInput.translate(-80, 10).rotateZ(0).opacity(1).step();
  54. this.setData({
  55. animPlus: animationPlus.export(),
  56. animCollect: animationcollect.export(),
  57. animTranspond: animationTranspond.export(),
  58. animInput: animationInput.export(),
  59. })
  60. },
  61. //收回动画
  62. takeback: function () {
  63. //plus逆时针旋转
  64. let animationPlus = wx.createAnimation({
  65. duration: 500,
  66. timingFunction: 'ease'
  67. })
  68. let animationcollect = wx.createAnimation({
  69. duration: 500,
  70. timingFunction: 'ease'
  71. })
  72. let animationTranspond = wx.createAnimation({
  73. duration: 500,
  74. timingFunction: 'ease'
  75. })
  76. let animationInput = wx.createAnimation({
  77. duration: 500,
  78. timingFunction: 'ease'
  79. })
  80. animationPlus.rotateZ(0).step();
  81. animationcollect.translate(0, 0).rotateZ(0).opacity(0).step();
  82. animationTranspond.translate(0, 0).rotateZ(0).opacity(0).step();
  83. animationInput.translate(0, 0).rotateZ(0).opacity(0).step();
  84. this.setData({
  85. animPlus: animationPlus.export(),
  86. animCollect: animationcollect.export(),
  87. animTranspond: animationTranspond.export(),
  88. animInput: animationInput.export(),
  89. })
  90. },

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/77090
推荐阅读
相关标签
  

闽ICP备14008679号