微信小程序实现敲木鱼

使用原生微信小程序编写的
直接贴代码
wxml文件

<view class="title">您的功德:{{value}}</view>
<view id="{{id}}">功德+1</view>
<image  src="https://clemmensen.top/static/muyu.png" bindtap="click" class="image {{classStyle}}"></image>
<audio poster="{{poster}}" name="{{name}}" author="{{author}}" src="{{src}}" id="myAudio" ></audio>
<audio poster="{{poster}}" name="{{name}}" author="{{author}}" src="https://clemmensen.top/static/28297622582.mp3" id="bg" ></audio>

js文件

// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    classStyle: '',
    value:0,
    id:'default',
    bg:null,
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    canIUseGetUserProfile: false,
    canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
  },
  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad() {

    this.audioCtx = wx.createAudioContext('myAudio');
    this.bg=wx.createAudioContext('bg');
    this.bg.play();
  },

  click() {
    this.setData({
      classStyle: 'animal',
      id:'font',
      value:this.data.value+1,
    });
    this.setData({
      src:'https://clemmensen.top/static/muyu.mp3',
    });
    this.audioCtx.play();

    
    setTimeout(() => {
      this.setData({
        classStyle: '',
        //id:'default'
      });
    }, 100);
    setTimeout(() => {
      this.setData({
        id:'default'
      });
    }, 500);
  },
})

wxss样式文件

/* pages/muyu/index.wxss */
page{
  background: black;
}
.animal{
  transform:scale(1.05);
}
.image{
  width:304rpx;
  height:221rpx ;
  margin-left: 223rpx;
  margin-top: 20rpx;
}
#font{
  color:white;
  height: 200px;
  animation: mymove 1s;
  position:absolute;
  opacity:0;
  margin-left: 250rpx;
}
#default{
  color:white;
  height: 200px;
  position:absolute;
  opacity:0;
  margin-left: 250rpx;
}
@keyframes mymove {
  from {top:100px;opacity:100;}
  to {top:50px;opacity:0;}
}
.title{
  margin-left: 250rpx;color:white; margin-top: 250rpx;
}

实现效果
在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值