yujianqiutian2023.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. Page({
  2. /**
  3. * 页面的初始数据
  4. */
  5. data: {
  6. // 背景音乐
  7. bgmusic: {
  8. music: null,
  9. playing: false
  10. },
  11. ads: null,
  12. hasLoadAdConfig: false,
  13. photoIndex: 0,
  14. examplePhotos: [
  15. 'ac_527831862795.jpeg',
  16. 'ac_527831968525.jpeg',
  17. 'ac_527832032890.jpeg',
  18. 'ac_527832064227.jpeg',
  19. 'ac_527832099230.jpeg',
  20. 'ac_527832214467.jpeg',
  21. 'ac_527832265952.jpeg',
  22. 'ac_527832389834.jpeg',
  23. 'ac_527832424179.jpeg',
  24. 'ac_527832663439.jpeg',
  25. ],
  26. imageWidths: [],
  27. imageHeights: [],
  28. imageStyles: [],
  29. page1BlockStyle: '',
  30. page1Block1Style: '',
  31. page1ImageStyle: ``,
  32. page2BlockStyle: '',
  33. page2Block1Style: '',
  34. page2ImageStyle: ``,
  35. page3BlockStyle: '',
  36. page3Block1Style: '',
  37. page3ImageStyle: ``,
  38. phudieBlockSytle: '', // 蝴蝶特效
  39. rhudieBlockSytle: '',
  40. yhudieBlockSytle: '',
  41. timeouts: []
  42. },
  43. /**
  44. * 生命周期函数--监听页面加载
  45. */
  46. onLoad(options) {
  47. this.initAnimation()
  48. },
  49. initAnimation() {
  50. this.setData({
  51. photoIndex: 0
  52. })
  53. this.showPage()
  54. },
  55. showPage() {
  56. const _this = this
  57. if (this.data.photoIndex === this.data.examplePhotos.length - 1) {
  58. // 图片轮询完重新开始
  59. this.setData({
  60. 'photoIndex': 0
  61. })
  62. }
  63. const pageIndex = this.data.photoIndex % 3 + 1
  64. const anStyle = this.data.photoIndex % 2 + 1
  65. const imageURL = `https://novel-video.hongdes.cn/kawaalbum/yujianqiutian2023/example/${this.data.examplePhotos[this.data.photoIndex]}`
  66. wx.getImageInfo({
  67. src: imageURL,
  68. success(res) {
  69. const imageWidth = res.width
  70. const imageHeight = res.height
  71. let blockStyle = ''
  72. if (imageWidth > imageHeight) {
  73. // 横版图片
  74. blockStyle = 'top:30%;'
  75. } else {
  76. // 竖版图片
  77. blockStyle = 'top:10%;'
  78. }
  79. _this.setData({
  80. [`page${pageIndex}BlockStyle`]: `${blockStyle}animation: show${anStyle}page-an 2s linear both`,
  81. [`page${pageIndex}Block1Style`]: `animation: show1page1-an 3s linear infinite`,
  82. [`page${pageIndex}ImageStyle`]: imageURL,
  83. })
  84. if (pageIndex === 1) {
  85. _this.setData({
  86. phudieBlockSytle: `animation: phudie_run 5s 2s ease-out both;`,
  87. rhudieBlockSytle: '',
  88. yhudieBlockSytle: ''
  89. })
  90. } else if (pageIndex === 2) {
  91. _this.setData({
  92. phudieBlockSytle: ``,
  93. rhudieBlockSytle: 'animation: rhudie_run 5s 2s ease-out both;',
  94. yhudieBlockSytle: ''
  95. })
  96. } else {
  97. _this.setData({
  98. phudieBlockSytle: ``,
  99. rhudieBlockSytle: '',
  100. yhudieBlockSytle: 'animation: yhudie_run 5s 2s ease-out both;'
  101. })
  102. }
  103. _this.data.timeouts.push(setTimeout(() => {
  104. _this.setData({
  105. [`page${pageIndex}BlockStyle`]: `animation: show${anStyle}page-out 2s linear both`,
  106. 'photoIndex': _this.data.photoIndex + 1
  107. })
  108. _this.showPage();
  109. }, 5000));
  110. }
  111. })
  112. },
  113. /**
  114. * 播放音乐
  115. */
  116. initBgMusic() {
  117. let _this = this
  118. if (!app.globalData.audioContext) {
  119. app.globalData.audioContext = wx.createInnerAudioContext()
  120. }
  121. // obeyMuteSwitch(仅在 iOS 生效)是否遵循静音开关,设置为 false 之后,即使是在静音模式下,也能播放声音
  122. wx.setInnerAudioOption({
  123. obeyMuteSwitch: false
  124. })
  125. // 设置音乐循环
  126. app.globalData.audioContext.loop = true
  127. // 监听音乐播放
  128. app.globalData.audioContext.onPlay(() => {
  129. _this.setData({
  130. 'bgmusic.playing': true
  131. })
  132. console.log('music play', _this.data.bgmusic.playing)
  133. })
  134. // 监听音乐暂停
  135. app.globalData.audioContext.onPause(() => {
  136. console.log('music pause')
  137. _this.setData({
  138. 'bgmusic.playing': false
  139. })
  140. })
  141. app.globalData.audioContext.src = this.data.bgmusic.music.url
  142. app.globalData.audioContext.play()
  143. },
  144. /**
  145. * 音乐播放按钮
  146. */
  147. musicPlayTap() {
  148. app.globalData.audioContext.paused ? app.globalData.audioContext.play() : app.globalData.audioContext.pause()
  149. },
  150. /**
  151. * 生命周期函数--监听页面显示
  152. */
  153. onShow() {
  154. },
  155. /**
  156. * 生命周期函数--监听页面隐藏
  157. */
  158. onHide() {
  159. },
  160. /**
  161. * 生命周期函数--监听页面卸载
  162. */
  163. onUnload() {
  164. this.clearTimeoutTask()
  165. },
  166. // 清除定时任务
  167. clearTimeoutTask() {
  168. this.data.timeouts.forEach(timeout => clearTimeout(timeout));
  169. },
  170. /**
  171. * 用户点击右上角分享
  172. */
  173. onShareAppMessage() {
  174. }
  175. })