index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. // pagesPublic/pages/tdcr/index.js
  2. const {imgUrl} = require('../api/request')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgPath: imgUrl + 'tdcr/',
  9. cursorGuys: [{
  10. left: 48,
  11. top: 1.5
  12. }, {
  13. left: 20,
  14. top: 4
  15. }],
  16. cursors: [{
  17. txt: '弹子石组团\nB8-1、B8-3、B9',
  18. top: -12,
  19. left: 28,
  20. dropTop: -1,
  21. dropLeft: 8.5
  22. }, {
  23. txt: '四公里\n棚户区地块',
  24. top: -21,
  25. left: 20,
  26. dropTop: 0,
  27. dropLeft: 1
  28. }, {
  29. txt: '茶园组团\nC01-16/02、\nC01-17/02',
  30. top: -43,
  31. left: 59,
  32. dropTop: 1,
  33. dropLeft: 2
  34. }],
  35. list: [{
  36. icon: 'icon-quyu.png',
  37. txt: '区域中心 得天独厚',
  38. top: 0,
  39. left: 12
  40. }, {
  41. icon: 'icon-house.png',
  42. txt: '南岸新区 宜居宜业',
  43. top: 1,
  44. left: 5
  45. }, {
  46. icon: 'icon-ai.png',
  47. txt: '资源富集 优势明显',
  48. top: 1,
  49. left: 0
  50. }, {
  51. icon: 'icon-car.png',
  52. txt: '立体交通 四通八达',
  53. top: 1,
  54. left: 12
  55. }, {
  56. icon: 'icon-bod.png',
  57. txt: '产业坚实 人才汇聚',
  58. top: 1,
  59. left: 20
  60. }],
  61. touchData: {
  62. flag: 0,
  63. lastX: 0,
  64. lastY: 0
  65. },
  66. animationData: {},
  67. currentIndex: 0,
  68. isAnimating: false
  69. },
  70. /**
  71. * 生命周期函数--监听页面加载
  72. */
  73. onLoad(options) {
  74. },
  75. /**
  76. * 生命周期函数--监听页面初次渲染完成
  77. */
  78. onReady() {
  79. this.initAnimations();
  80. setTimeout(() => {
  81. this.startAnimationLoop();
  82. }, 500);
  83. },
  84. /**
  85. * 生命周期函数--监听页面显示
  86. */
  87. onShow() {
  88. },
  89. /**
  90. * 生命周期函数--监听页面隐藏
  91. */
  92. onHide() {
  93. },
  94. /**
  95. * 生命周期函数--监听页面卸载
  96. */
  97. onUnload() {
  98. },
  99. /**
  100. * 页面相关事件处理函数--监听用户下拉动作
  101. */
  102. onPullDownRefresh() {
  103. },
  104. /**
  105. * 页面上拉触底事件的处理函数
  106. */
  107. onReachBottom() {
  108. },
  109. /**
  110. * 用户点击右上角分享
  111. */
  112. onShareAppMessage() {
  113. },
  114. handleTouchend() {
  115. let touchData = this.data.touchData
  116. touchData.flag = 0
  117. //停止滑动
  118. this.setData({
  119. touchData
  120. })
  121. },
  122. handleTouchstart(event) {
  123. this.setData({
  124. touchData: {
  125. flag: 0,
  126. lastX: event.changedTouches[0].pageX,
  127. lastY: event.changedTouches[0].pageY
  128. }
  129. })
  130. },
  131. handleTouchmove(event) {
  132. let touchData = this.data.touchData
  133. if (touchData.flag !== 0) {
  134. return;
  135. }
  136. let currentX = event.changedTouches[0].pageX;
  137. let currentY = event.changedTouches[0].pageY;
  138. let tx = currentX - touchData.lastX;
  139. let ty = currentY - touchData.lastY;
  140. //左右方向偏移大于上下偏移认为是左右滑动
  141. if (Math.abs(tx) - Math.abs(ty) > 5) {
  142. // 向左滑动
  143. if (tx < 0) {
  144. // 如果到最右侧
  145. console.log('向左滑动');
  146. touchData.flag = 1;
  147. wx.navigateTo({
  148. url: './tdcr-list/index',
  149. })
  150. } else if (tx > 0) {
  151. // 如果到最左侧
  152. touchData.flag = 2;
  153. console.log('向右滑动');
  154. }
  155. }
  156. //将当前坐标进行保存以进行下一次计算
  157. touchData.lastX = currentX;
  158. touchData.lastY = currentY;
  159. this.setData({
  160. touchData
  161. })
  162. },
  163. initAnimations: function() {
  164. const list = this.data.list;
  165. list.forEach((item, index) => {
  166. this.createAnimation(index);
  167. });
  168. },
  169. createAnimation: function(index) {
  170. const animation = wx.createAnimation({
  171. duration: 1000, // 动画持续时间
  172. timingFunction: 'ease', // 动画效果
  173. });
  174. this.setData({
  175. ['animationData[' + index + ']']: animation.export(),
  176. });
  177. },
  178. startAnimationLoop: function() {
  179. const list = this.data.list;
  180. const currentIndex = this.data.currentIndex;
  181. if (currentIndex < list.length) {
  182. if (this.data.isAnimating) return;
  183. this.setData({
  184. isAnimating: true
  185. })
  186. // 获取当前索引的动画对象
  187. const animation = wx.createAnimation({
  188. duration: 1000,
  189. timingFunction: 'linear',
  190. });
  191. // 放大动画
  192. animation.scale(1.2, 1.2).step();
  193. // 更新动画数据
  194. this.setData({
  195. ['animationData[' + currentIndex + ']']: animation.export(),
  196. isAnimating: this.data.isAnimating
  197. });
  198. // 设置动画结束后回调
  199. setTimeout(() => {
  200. // 恢复到原始大小
  201. const restoreAnimation = wx.createAnimation({
  202. duration: 1000,
  203. timingFunction: 'linear',
  204. });
  205. restoreAnimation.scale(1, 1).step();
  206. this.setData({
  207. ['animationData[' + currentIndex + ']']: restoreAnimation.export(),
  208. isAnimating: false
  209. });
  210. // 动画结束后,索引递增,如果到达列表末尾,则重置为0
  211. this.setData({
  212. currentIndex: (currentIndex + 1) % list.length,
  213. });
  214. if ((currentIndex + 1) % list.length == 0 && currentIndex != 0) {
  215. setTimeout(() => {
  216. this.startAnimationLoop();
  217. }, 2000);
  218. } else {
  219. this.startAnimationLoop();
  220. }
  221. }, 1500);
  222. }
  223. },
  224. })