一、首先我先介绍一下,我们要做一个什么样的项目功能

  1. 项目功能就是一个音频点击播放,当点击为播放的状态时,一个音频的动图出现,而且是可以跟随着手指的滑动而滑动,而且,在滑动动图的时候,当前下的页面是不可以跟随着我的滑动而上下滚动,当停止滑动的时候,音频动图停靠在手机的左侧或者右侧,而当前下的页面是可以上下滚动的,功能介绍到此为止,下面我们说一下思路。

二、我们做这个功能,第二步就是要想思路

  1. 思路就是,利用微信中的滑动事件,外加控制css样式,来完成这个功能。

三、这是项目的ui图,废话不多说,直接撸代码。

  1. 项目样图



四、index.wxml、index.wxss、index.js页面代码

  1. *index.wxml页面*
  1. <!-- 搜索 -->
  2. <view class='home_srh'>
  3. <view class='srh_box' bindtap='srhBox'>
  4. <image class='srh_box_img' src='../../img/home_search.png'></image>
  5. <view class='srh_box_text'>开心奶奶</view>
  6. </view>
  7. </view>
  8. <!-- 音频分类 -->
  9. <view class='home_ban'>
  10. <!-- 轮播图 -->
  11. <view class="page-section">
  12. <swiper circular="true" previous-margin="44rpx" next-margin="44rpx">
  13. <!-- <block wx:for="{{}}" wx:key=""> -->
  14. <swiper-item>
  15. <view class="swiper-item">
  16. <audio src="http://img.tukuppt.com/preview_music/00/00/60/yulan-5b87c00c59d402663.mp3" id="myAudio" loop></audio>
  17. <view class='audio_box'>
  18. <button bindtap='audioPlay' wx:if="{{adply1}}" class='audio_play'>
  19. <image src='../../img/home_adplay.png' ></image>
  20. </button>
  21. <button bindtap='audioPause' wx:if="{{adply2}}" class='audio_play'>
  22. <image src='../../img/home_adstop.png' ></image>
  23. </button>
  24. </view>
  25. <view class='audio_next'>
  26. <image src='../../img/audio_next.png'></image>
  27. </view>
  28. <view class='audio_collect'>
  29. <button bindtap='audioColy' wx:if="{{adcol1}}" class='audio_coly'>
  30. <image src='../../img/audio_nocollect.png'></image>
  31. </button>
  32. <button bindtap='audioColn' wx:if="{{adcol2}}" class='audio_coly'>
  33. <image src='../../img/audio_collect.png'></image>
  34. </button>
  35. </view>
  36. <view class='audio_text'>开心奶奶——小小探险家</view>
  37. </view>
  38. </swiper-item>
  39. <swiper-item>
  40. <view class="swiper-item">
  41. <audio src="http://img.tukuppt.com/preview_music/00/00/60/yulan-5b87c00c59d402663.mp3" id="myAudio" loop></audio>
  42. <view class='audio_box'>
  43. <button bindtap='audioPlay' wx:if="{{adply1}}" class='audio_play'>
  44. <image src='../../img/home_adplay.png' ></image>
  45. </button>
  46. <button bindtap='audioPause' wx:if="{{adply2}}" class='audio_play'>
  47. <image src='../../img/home_adstop.png' ></image>
  48. </button>
  49. </view>
  50. <view class='audio_next'>
  51. <image src='../../img/audio_next.png'></image>
  52. </view>
  53. <view class='audio_collect'>
  54. <button bindtap='audioColy' wx:if="{{adcol1}}" class='audio_coly'>
  55. <image src='../../img/audio_nocollect.png'></image>
  56. </button>
  57. <button bindtap='audioColn' wx:if="{{adcol2}}" class='audio_coly'>
  58. <image src='../../img/audio_collect.png'></image>
  59. </button>
  60. </view>
  61. <view class='audio_text'>开心奶奶——小小探险家</view>
  62. </view>
  63. </swiper-item>
  64. <!-- </block> -->
  65. </swiper>
  66. </view>
  67. ----------
  68. > 重点!!!!
  69. <!-- 音频动图 -->
  70. <view class='{{ home_back }}' catchtouchmove='true' >
  71. <view class='audio_fre' wx:if="{{ adFre }}" bindtouchmove="handletouchmove" bindtouchend="handletouchend" style = "top:{{top}}px; left: {{left}}px; right: {{right}}px">
  72. <image class='audio_fre1' src='../../img/audio_back.png'></image>
  73. <image class='audio_fre2' src='../../img/audio_fre.gif'></image>
  74. </view>
  75. </view>
  76. ----------
  77. <!-- 分类 -->
  78. <view class='menu_ul'>
  79. <view class='menu_li' id="0" bindtap='menuLi'>
  80. <image src='../../img/recom.png'></image>
  81. <view class='menu_text'>推荐故事</view>
  82. </view>
  83. <view class='menu_li' id="1" bindtap='menuLi'>
  84. <image src='../../img/boy_icon.png'></image>
  85. <view class='menu_text'>男孩</view>
  86. </view>
  87. <view class='menu_li' id="2" bindtap='menuLi'>
  88. <image src='../../img/girl_icon.png'></image>
  89. <view class='menu_text'>女孩</view>
  90. </view>
  91. </view>
  92. </view>
  93. <!-- 儿童故事 -->
  94. <view class='child_story'>
  95. <view class='story_ul' wx:if="{{curr_index == 0}}">
  96. <view class='story_li' bindtap='storySec'>
  97. <view class='story_li_img'>
  98. <image class='story_li_img1' src='../../img/weekend-first.png'></image>
  99. <image class='story_li_img2' src='../../img/pay_icon.png'></image>
  100. </view>
  101. <view class='st_li_tit b'>童话故事里的小智慧</view>
  102. <view class='st_li_sec'>小智慧,大智慧</view>
  103. </view>
  104. </view>
  105. <view class='story_ul' wx:if="{{curr_index == 1}}">
  106. <view class='story_li' bindtap='storySec'>
  107. <view class='story_li_img'>
  108. <image class='story_li_img1' src='../../img/weekend-first.png'></image>
  109. <!-- <image class='story_li_img2' src='../../img/pay_icon.png'></image> -->
  110. </view>
  111. <view class='st_li_tit b'>童话故事里的小智慧</view>
  112. <view class='st_li_sec'>小智慧,大智慧</view>
  113. </view>
  114. </view>
  115. <view class='story_ul' wx:if="{{curr_index == 2}}">
  116. <view class='story_li' bindtap='storySec'>
  117. <view class='story_li_img'>
  118. <image class='story_li_img1' src='../../img/weekend-first.png'></image>
  119. <image class='story_li_img2' src='../../img/pay_icon.png'></image>
  120. </view>
  121. <view class='st_li_tit b'>童话故事里的小智慧</view>
  122. <view class='st_li_sec'>小智慧,大智慧</view>
  123. </view>
  124. </view>
  125. </view>
  1. *index.wxss样式*
  1. /**index.wxss**/
  2. .home_back1{
  3. width: 100%;
  4. }
  5. .home_back2{
  6. position: fixed;
  7. top: 0;
  8. left: 0;
  9. right: 0;
  10. bottom: 0;
  11. z-index: 10;
  12. }
  13. /* 搜索 */
  14. .home_srh {
  15. width: 100%;
  16. height: 74rpx;
  17. padding-top: 20rpx;
  18. background: #fff;
  19. border-bottom: 1rpx solid #e8e8e8;
  20. }
  21. .home_srh .srh_box {
  22. width: 690rpx;
  23. height: 54rpx;
  24. margin: 0 auto;
  25. box-shadow: 0 0 10rpx 2rpx #f1f1f1;
  26. border-radius: 50rpx;
  27. display: flex;
  28. align-items: center;
  29. }
  30. .home_srh .srh_box .srh_box_img {
  31. width: 24rpx;
  32. height: 26rpx;
  33. display: inline-block;
  34. margin-left: 32rpx;
  35. margin-right: 20rpx;
  36. }
  37. .home_srh .srh_box .srh_box_text {
  38. font-size: 24rpx;
  39. color: #999;
  40. }
  41. /* 音频分类 */
  42. /* banner图 */
  43. .home_ban{
  44. width: 100%;
  45. height: 422rpx;
  46. background: #fff;
  47. padding-top: 18rpx;
  48. }
  49. .home_ban .page-section{
  50. width: 100%;
  51. height: 258rpx;
  52. position:relative;
  53. z-index: 2;
  54. }
  55. .home_ban .page-section .swiper-item{
  56. width: 630rpx;
  57. height: 258rpx;
  58. margin: 0 auto;
  59. position: relative;
  60. display: block;
  61. }
  62. .home_ban .page-section .swiper-item audio{
  63. width: 630rpx;
  64. height: 258rpx;
  65. display: block;
  66. background: #ccc;
  67. }
  68. .home_ban .page-section .swiper-item .audio_box {
  69. width: 90rpx;
  70. height: 90rpx;
  71. position: absolute;
  72. left: 50%;
  73. top: 50%;
  74. margin-left: -45rpx;
  75. margin-top: -45rpx;
  76. }
  77. .home_ban .page-section .swiper-item .audio_box .audio_play {
  78. width: 90rpx;
  79. height: 90rpx;
  80. display: block;
  81. background: rgba(0,0,0,0);
  82. }
  83. .home_ban .page-section .swiper-item .audio_box .audio_play image{
  84. width: 90rpx;
  85. height: 90rpx;
  86. display: block;
  87. }
  88. .home_ban .page-section .swiper-item .audio_next {
  89. width: 60rpx;
  90. height: 60rpx;
  91. position: absolute;
  92. top: 50%;
  93. margin-top: -30rpx;
  94. right: 169rpx;
  95. }
  96. .home_ban .page-section .swiper-item .audio_next image {
  97. width: 60rpx;
  98. height: 60rpx;
  99. display: block;
  100. }
  101. .home_ban .page-section .swiper-item .audio_collect {
  102. width: 60rpx;
  103. height: 60rpx;
  104. position: absolute;
  105. top: 50%;
  106. margin-top: -30rpx;
  107. right: 169rpx;
  108. }
  109. .home_ban .page-section .swiper-item .audio_collect image {
  110. width: 60rpx;
  111. height: 60rpx;
  112. display: block;
  113. }
  114. .home_ban .page-section .swiper-item .audio_collect {
  115. width: 60rpx;
  116. height: 60rpx;
  117. position: absolute;
  118. top: 50%;
  119. margin-top: -30rpx;
  120. left: 169rpx;
  121. }
  122. .home_ban .page-section .swiper-item .audio_collect .audio_coly {
  123. width: 60rpx;
  124. height: 60rpx;
  125. display: block;
  126. background: rgba(0,0,0,0);
  127. }
  128. .home_ban .page-section .swiper-item .audio_collect .audio_coly image {
  129. width: 60rpx;
  130. height: 60rpx;
  131. display: block;
  132. }
  133. .home_ban .page-section .swiper-item .audio_text{
  134. width: 100%;
  135. font-size: 28rpx;
  136. color: #fff;
  137. text-align: center;
  138. position: absolute;
  139. bottom: 26rpx;
  140. }
  141. /* 音频小白点 */
  142. .audio_fre {
  143. width: 108rpx;
  144. height: 108rpx;
  145. position: fixed;
  146. z-index: 99;
  147. }
  148. .audio_fre .audio_fre1 {
  149. width: 104rpx;
  150. height: 104rpx;
  151. display: block;
  152. border-radius: 100%;
  153. border: 2rpx solid #fff;
  154. }
  155. .audio_fre .audio_fre2 {
  156. width: 60rpx;
  157. height: 60rpx;
  158. position: absolute;
  159. top: 50%;
  160. margin-top: -30rpx;
  161. left: 50%;
  162. margin-left: -30rpx;
  163. }
  164. /* 菜单分类 */
  165. .menu_ul {
  166. width: 100%;
  167. height: 164rpx;
  168. }
  169. .menu_ul .menu_li {
  170. width: 33.3%;
  171. height: 164rpx;
  172. float: left;
  173. text-align: center;
  174. }
  175. .menu_ul .menu_li:nth-child(1) image{
  176. width: 78rpx;
  177. height: 80rpx;
  178. display: block;
  179. margin: 0 auto;
  180. margin-top: 23rpx;
  181. }
  182. .menu_ul .menu_li:nth-child(2) image{
  183. width: 74rpx;
  184. height: 97rpx;
  185. display: block;
  186. margin: 0 auto;
  187. margin-top: 8rpx;
  188. }
  189. .menu_ul .menu_li:nth-child(3) image{
  190. width: 73rpx;
  191. height: 96rpx;
  192. display: block;
  193. margin: 0 auto;
  194. margin-top: 8rpx;
  195. }
  196. .menu_ul .menu_li .menu_text{
  197. width: 100%;
  198. text-align: center;
  199. font-size: 24rpx;
  200. color: #343434;
  201. margin-top: 10rpx;
  202. }
  203. /* 儿童故事 */
  204. .child_story {
  205. width: 100%;
  206. margin-top: 8rpx;
  207. background: #fff;
  208. }
  209. .child_story .story_ul {
  210. padding: 0 32rpx;
  211. padding-top: 30rpx;
  212. overflow: hidden;
  213. }
  214. .child_story .story_ul .story_li {
  215. width: 330rpx;
  216. float: left;
  217. margin-right: 26rpx;
  218. margin-bottom: 30rpx;
  219. }
  220. .child_story .story_ul .story_li:nth-child(2n) {
  221. margin-right: 0;
  222. }
  223. .child_story .story_ul .story_li .story_li_img {
  224. width: 330rpx;
  225. height: 210rpx;
  226. border-radius: 14rpx;
  227. position: relative;
  228. overflow: hidden;
  229. }
  230. .child_story .story_ul .story_li .story_li_img .story_li_img1{
  231. width: 330rpx;
  232. height: 210rpx;
  233. display: block;
  234. }
  235. .child_story .story_ul .story_li .story_li_img .story_li_img2{
  236. width: 95rpx;
  237. height: 32rpx;
  238. display: block;
  239. position: absolute;
  240. top: 0;
  241. left: 0;
  242. }
  243. .child_story .story_ul .story_li .st_li_tit {
  244. width: 90%;
  245. font-size: 26rpx;
  246. color: #212121;
  247. margin-top: 18rpx;
  248. padding: 0 5%;
  249. overflow: hidden;
  250. text-overflow: ellipsis;
  251. white-space: nowrap;
  252. letter-spacing: 0.4rpx;
  253. }
  254. .child_story .story_ul .story_li .st_li_sec {
  255. width: 90%;
  256. font-size: 18rpx;
  257. color: #999;
  258. margin-top: 6rpx;
  259. padding: 0 5%;
  260. letter-spacing: 0.2rpx;
  261. }
  1. *index.js页面*
  1. //index.js
  2. var app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. adply1: true,
  9. adply2: false,
  10. adcol1: true,
  11. adcol2: false,
  12. adFre: false,
  13. funBun: false,
  14. curr_index: 0,
  15. screenHeight: 0,
  16. screenWidth: 0,
  17. top: 65,
  18. left: 300,
  19. right: 0,
  20. home_back: 'home_back1'
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. //获取屏幕宽高
  27. var that = this;
  28. wx.getSystemInfo({
  29. success: function (res) {
  30. console.log(res.windowWidth)//手机可用屏幕宽度
  31. console.log(res.windowHeight)//手机可用屏幕高度
  32. that.setData({
  33. screenHeight: res.windowHeight,
  34. screenWidth: res.windowWidth,
  35. });
  36. }
  37. });
  38. },
  39. /**
  40. * 生命周期函数--监听页面初次渲染完成
  41. */
  42. onReady: function (e) {
  43. let that = this;
  44. that.audioCtx = wx.createAudioContext('myAudio')
  45. },
  46. /**
  47. * 生命周期函数--监听页面显示
  48. */
  49. onShow: function () {
  50. },
  51. /**
  52. * 生命周期函数--监听页面隐藏
  53. */
  54. onHide: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面卸载
  58. */
  59. onUnload: function () {
  60. },
  61. /**
  62. * 页面相关事件处理函数--监听用户下拉动作
  63. */
  64. onPullDownRefresh: function () {
  65. },
  66. /**
  67. * 页面上拉触底事件的处理函数
  68. */
  69. onReachBottom: function () {
  70. },
  71. /**
  72. * 用户点击右上角分享
  73. */
  74. onShareAppMessage: function () {
  75. },
  76. /**
  77. * 跳转搜索页面
  78. */
  79. srhBox: function () {
  80. let that = this;
  81. wx.navigateTo({
  82. url: '../search/index',
  83. })
  84. },
  85. /**
  86. * 点击播放
  87. */
  88. audioPlay: function () {
  89. var that = this;
  90. that.audioCtx.play();
  91. that.setData({
  92. adply1: false,
  93. adply2: true,
  94. adFre: true,
  95. // isScroll: that.data.isScroll
  96. })
  97. },
  98. /**
  99. * 点击暂停
  100. */
  101. audioPause: function () {
  102. var that = this;
  103. that.audioCtx.pause();
  104. that.setData({
  105. adply1: true,
  106. adply2: false,
  107. adFre: false,
  108. // isScroll: that.data.isScroll
  109. })
  110. },
  111. /**
  112. * 点击收藏
  113. */
  114. audioColy: function () {
  115. var that = this;
  116. that.setData({
  117. adcol1: false,
  118. adcol2: true,
  119. })
  120. },
  121. /**
  122. * 点击未收藏
  123. */
  124. audioColn: function () {
  125. var that = this;
  126. that.setData({
  127. adcol1: true,
  128. adcol2: false,
  129. })
  130. },
  131. /**
  132. * 跳转故事详情
  133. */
  134. storySec: function () {
  135. let that = this;
  136. wx.navigateTo({
  137. url: '../audio/index',
  138. })
  139. },
  140. /**
  141. * 点击切换
  142. */
  143. menuLi: function (e) {
  144. let that = this;
  145. // console.log (e);
  146. let id = e.currentTarget.id;
  147. that.setData({
  148. curr_index: id
  149. })
  150. },
  151. /**
  152. * 音频小白点滑动
  153. */
  154. //滑动移动事件
  155. handletouchmove: function (e) {
  156. let that = this;
  157. let clientX = e.touches[0].clientX;
  158. let clientY = e.touches[0].clientY;
  159. //屏幕边界判断
  160. if (clientX < 20 || clientY < 20)
  161. return;
  162. if (clientX > that.data.screenWidth - 20)
  163. return;
  164. if (clientY > that.data.screenHeight - 20)
  165. return;
  166. that.setData({
  167. left: e.touches[0].clientX - 20,
  168. top: e.touches[0].clientY - 20,
  169. right: e.touches[0].clientX - 20,
  170. home_back: 'home_back2'
  171. })
  172. },
  173. //滑动结束事件
  174. handletouchend: function (e) {
  175. let that = this;
  176. if ( that.data.left < (that.data.screenWidth - 60) / 2 ) {
  177. that.setData({
  178. left: 0,
  179. home_back: 'home_back1'
  180. })
  181. } else {
  182. that.setData({
  183. left: that.data.screenWidth - 60,
  184. right: 0,
  185. home_back: 'home_back1'
  186. })
  187. }
  188. }
  189. })

用小程序做一个类似于苹果AssistiveTouch功能的更多相关文章

  1. 小程序做一个能够左右滑动切换的多tab页面

    主要原理:使用 <swiper> 和 <scroll-view> 组件 代码片段: https://developers.weixin.qq.com/s/mLx4FWmF757 ...

  2. 用微信小程序做一个小电商 sku

    效果展示图 功能点概述 图一功能点有 搜索 轮播图 商品展示 图二功能点 导航栏 加入购物车 图四功能点 评论点 图五购物车 复选框 ( 全选全不选 ) 即点即改 总计结算 功能详解 1.A(搜索) ...

  3. 微信小程序发布一个月,世界并没有什么不同

    从某种意义上说,在张小龙身上,最可怕的事情莫过于微信小程序发布一个月,一开始的大红大紫居然渐归沉寂,曾经的风光无限已无人谈起,世界并没有什么不同. 这真像一场噩梦,一切都可怕地颠倒了.一款微信的战略级 ...

  4. 微信小程序0.11.122100版本新功能解析

    微信小程序0.11.122100版本新功能解析   新版本就不再吐槽了,整的自己跟个愤青似的.人老了,喷不动了,把机会留给年轻人吧.下午随着新版本开放,微信居然破天荒的开放了开发者论坛.我很是担心官方 ...

  5. 微信小程序调用用百度地图天气功能

    #小程序之调用百度地图天气功能 本篇博客主要介绍小程序在百度地图中获取天气信息,如有不全请指出.下面先上效果图 主要内容 百度地图API的个人密钥,也就是AK 请求百度地图API接口数据 获取到的信息 ...

  6. 微信小程序禁止刷新之后苹果端还可以下拉的问题

    一.问题描述 最近在做一个小程序项目,需要禁止下拉刷新,于是在page.json里面添加了这段话 "enablePullDownRefresh":false 全局关闭下拉刷新,这段 ...

  7. 用微信小程序做H5游戏尝试

    微信小程序发布后,公司虽然没有拿到第一批内测资格,但作为微信亲密合作伙伴,一定要第一时间去尝试啦.现在微信小程序刚发布还在测试阶段,可以说是1.0版本,所以框架和结构内容都还不多,相关的文档跟微信AP ...

  8. Westore 1.0 正式发布 - 小程序框架一个就够

    世界上最小却强大的小程序框架 - 100多行代码搞定全局状态管理和跨页通讯 Github: https://github.com/dntzhang/westore 众所周知,小程序通过页面或组件各自的 ...

  9. 微信小程序创建一个新项目

    1. 新建一个文件夹. 2. 打开微信小程序开发工具,导入新建文件夹:然后输入创建的appId:会自动生成一个project.config.json,打开这个文件,会看到appid这个字段. 3.可以 ...

随机推荐

  1. 解决kubeadm部署kubernetes集群镜像问题

    kubeadm 是kubernetes 的集群安装工具,能够快速安装kubernetes 集群.kubeadm init 命令默认使用的docker镜像仓库为k8s.gcr.io,国内无法直接访问,需 ...

  2. CSS元素隐藏

    { display: none; /* 不占据空间,无法点击 */ } /*************************************************************** ...

  3. js移动端滑动效果

    移动端触屏滑动的效果其实就是图片轮播,在PC的页面上很好实现,绑定click和mouseover等事件来完成.但是在移动设备上,要实现这种轮播的效果,就需要用到核心的touch事件.处理touch事件 ...

  4. Blue Star(日剧:今夜 可否拥你入怀歌词)

    BLUE STAR-COLOR CREATION Oh I Know I need you in my life ひさしぶりの 译:时隔许久的 やわらかなかせがふきぬける 清风温柔吹拂 むねのおくの ...

  5. python学习之不要在列表迭代的时候进行增删操作

    注意:列表不能在for循环时使用remove方法 li = [11,22,33,44] for i in li : li.remove(i) print (li) #输出 [22, 44] ​ for ...

  6. 【Qt开发】QTableWidget的详细设置

    在使用Qt不多的日子里,已经两次用到了QTableWidget这个控件,也慢慢的习惯和喜欢上了它.再使用QTableWidget的时候,已不像刚开始使用时的迷茫.嗯嗯.现在就来总结总结我与QTable ...

  7. 几个关于json序列化 的注解

    一.@JsonProperty 1.此注解用于属性上,作用是把该属性的名称序列化为另外一个名称.例如: @JsonProperty("name") private String N ...

  8. POJ - 2421 Constructing Roads(最小生成树&并查集

    There are N villages, which are numbered from 1 to N, and you should build some roads such that ever ...

  9. [BZOJ2144][国家集训队2011]跳跳棋

    题目描述 跳跳棋是在一条数轴上进行的.棋子只能摆在整点上. 每个点不能摆超过一个棋子. 我们用跳跳棋来做一个简单的游戏:棋盘上有3颗棋子,分别在\(a\),\(b\),\(c\)这三个位置. 我们要通 ...

  10. hibernate update-->参数绑定

    Hibernate 更新数据库 参数绑定总结: 一.query.setParameter(属性名,真实值,类型); String hql="update User u set u.userN ...